【问题标题】:How to connect socket.io in angular 10?如何以角度 10 连接 socket.io?
【发布时间】:2021-10-21 03:21:30
【问题描述】:

我在角度 10 中使用带有 @types/socket.io-client 的 socket.io-client

 import * as io from 'socket.io-client';

 private socket;
 private url = 'https://chat.domain.com';

 ngOnInit(): void {

    this.socket = io(this.url);
    console.log("socket =============>>",this.socket);
}

但每次都出现同样的错误,请参阅下面的回复

谁来帮帮我

【问题讨论】:

    标签: node.js socket.io angular10 connectivity


    【解决方案1】:
     npm install socket.io-client@2.3.0
    
     import io from 'socket.io-client';
    
     this.socket = io("http://localhost:8080", {});
      
     console.log(this.socket);
    

    你必须安装客户端socket版本和服务器端socket版本需要相同。

    【讨论】:

    • 好的,我检查一下
    猜你喜欢
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 2021-11-05
    • 2019-03-05
    • 2020-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多