[Vuejs]-Whats the problem with the socketio connection?

1👍

It looks like socket.io is failing to establish a webSocket connection and has never advanced out of polling. By default, a socket.io connection starts with http polling and after a bit of negotiation with the server, it attempts to establish a webSocket connection. If that succeeds, it stops doing the polling and uses only the webSocket connection. If the the webSocket connection fails, it just keeps doing the polling.

Here are some reasons that can happen:

  1. You have a mismatched version of socket.io in client and server.
  2. You have some piece of infrastructure (proxy, firewall, load balancer, etc…) in between client and server that is not letting webSocket connections through.
  3. You’ve attached more than one socket.io server handler to the same web server. You can’t do that as the communication will get really messed up as multiple server handlers try to respond to the same client.

As a test, you could force the client to connect only with webSocket (no polling at all to start) and see if the connection fails:

let socket = io(yourURL, {transports: ["websocket"]})'
socket.on('connect', () => {console.log("connected"});
socket.on('connect_error', (e) => {console.log("connect error: ", e});
socket.on('connect_timeout', (e) => {console.log("connect timeout: ", e});

Leave a comment