NODEJS - Websocket return Error: read ECONNRESET when refreshing browser
NODEJS - Websocket return Error: read ECONNRESET when refreshing browser
我正在使用带有 restify 服务器的 nodeJS。我以这种方式使用 websocket:
wss.on('connection', (ws) => {
ws.on('message', handlers.messages.index.websocket);
});
wss.on("error", (err) => {
console.log(err.stack);
});
这是我的 angular 客户服务:
@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);
});
});
希望对您有所帮助
我正在使用带有 restify 服务器的 nodeJS。我以这种方式使用 websocket:
wss.on('connection', (ws) => {
ws.on('message', handlers.messages.index.websocket);
});
wss.on("error", (err) => {
console.log(err.stack);
});
这是我的 angular 客户服务:
@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);
});
});
希望对您有所帮助