我正在使用nodeJS和restify服务器。我这样使用websocket:
wss.on('connection', (ws) => {
ws.on('message', handlers.messages.index.websocket);
});
wss.on("error", (err) => {
console.log(err.stack);
});
这是我的角度客户服务:
@Injectable()
export class MessagesService {
private socket: WebSocket;
constructor() {
this.socket = new WebSocket(configApp.socket_url);
}
OnDestroy() {
this.socket.close();
}
send(str) {
this.socket.send(str);
}
}
当我刷新浏览器时,我收到了错误Error: read ECONNRESET
。它说我没有处理错误,但我认为这是处理它的方法。
我做错了什么?
谢谢你们!
我终于成功地使这些套接字工作了。
我应该这样做:
wss.on('connection', (ws) => {
ws.on('message', handlers.messages.index.websocket);
ws.on("error", (err) => {
console.log(err.stack);
});
});
希望它会有所帮助