Yoann Picquenot
Yoann Picquenot

Reputation: 660

NODEJS - Websocket return Error: read ECONNRESET when refreshing browser

I am using a nodeJS with restify server. I am using websocket this way:

wss.on('connection', (ws) => {
    ws.on('message', handlers.messages.index.websocket);
  });

wss.on("error", (err) => {
    console.log(err.stack);
  });

Here's my angular client service:

@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);
  }

}

I got the error Error: read ECONNRESET when I am refreshing my browser. It says I didn't handle the error but I think it's the way to handle it.

What did I do wrong?

Thank you all!

Upvotes: 1

Views: 7130

Answers (1)

Yoann Picquenot
Yoann Picquenot

Reputation: 660

I finally succeeded making these sockets working.

I should have done this:

wss.on('connection', (ws) => {
  ws.on('message', handlers.messages.index.websocket);
  ws.on("error", (err) => {
    console.log(err.stack);
  });
});

Hope it'll help

Upvotes: 3

Related Questions