如何在Ionic 3和角4中使用Websocket?
我尝试了类socket.io-client,但是如果我像这样连接websocket
this.socket = io(this.urls.websocket,{transports: ['websocket']};this.socket未定义,服务器上的用户显示为已连接。断开将不会触发。
如果我像这样使用集成的Websocket类
this.socket = new WebSocket(this.urls.websocket,['websocket']);
console.log("Socket ready state" + this.socket.readyState);
console.log("Socket:" + console.dir(this.socket));服务器上的套接字也显示为已连接,不会触发断开连接,但在客户端,我收到一条错误消息:
到'ws://192.168.0.10:8000/node/test.js‘的WebSocket连接失败:连接在收到握手响应之前已关闭
this.socket在连接模式(第2行)中跟踪连接线,如果我第二次记录错误(第3行),则它在客户端断开连接。在服务器上,它将仍然显示为连接和断开不会被触发。
与其他客户,如其他菜鸟,我没有任何问题,一切都正常。
发布于 2018-02-24 15:13:30
我想你很想念io.connect。
试试这个:
import * as io from 'socket.io-client';
this.socket = io.connect(this.socketURL);https://stackoverflow.com/questions/48951450
复制相似问题