Failed to connect to socket.io web connector (last chrome)

After installing node.js, I went after this tutorial to start a simple chat server. It was very easy to configure and work, but I noticed two problems:

1.) I get this warning from socket.io

info - socket.io started debug - served static /socket.io.js debug - client authorized info - handshake authorized 1385647068766475337 debug - setting request GET /socket.io/1/websocket/1385647068766475337 debug - set heartbeat interval for client 1385647068766475337 warn - websocket connection invalid 

This makes no sense to me because I did not touch anything with socket.io and I use the latest version of chrome (23), which I know supports websockets (I can successfully connect to them using PHP-WebSockets). It still uses XHR, but I'm really interested in working with Websocket functionality.

2.) When I switch to localhost: 8080 to connect to the chat server, it takes about 7-8 seconds for it to ask me for my name and actually connect me to the server. I have a feeling that this could happen because he is returning to XHR, but I really know little about it, so I can’t say it. Any thoughts?

+4
source share
3 answers

I saw this behavior when using an older version of socket.io with later chrome builds (and other browsers). This will be a timeout, then a return to XP polling. To test your version of the socket.io library that you use, enter your shell type (linux / unix):

 npm ls| grep socket.io 

And he should tell you the version. The latter at the moment is 0.9.13, which works.

If you are using the tutorial from http://psitsmike.com , please note that the package.json file rigidly sets the older version of socket.io, t to work with the latest browsers.

Hope this helps.

+2
source

I also encountered similar problems.

Your business -

  • Try deleting cookies, sometimes the xhr-poll parameter, which was set successfully, is stored in cookies and is reused the next time. A similar question was answered here
  • Also debug - served static /socket.io.js sometimes occurs when the socket.io file is incorrectly specified in the html or jade template file. Try to fix the script src link if it is erroneous. It should be something like - var socket = io.connect('http://localhost:3000'); OR you can also try deleting the link together, like this - var socket = io.connect();

Hope this helps.

0
source

I had the same problem. it may be old. but My setup is on digitalocean. that usually people who run node applications on the same server use nginx to listen on the port and node under their own dedicated port. nginx did not redirect the websocket port to node, but only port 80, from which nodejs was not initialized.

http://nginx.org/en/docs/http/websocket.html

You need to make sure your nginx is configured correctly for this.

I just added a port to io.connect, connecting directly to the node server and avoiding nginx.

0
source

Source: https://habr.com/ru/post/956978/


All Articles