1

I want to create a websocket server. I heard that socket.io is a good choice.

I tried socket.io with nodejs(v4.4.7) (npm install --save socket.io), using its sample server side code. A little confused why the client side code is using "http://" rather than "ws://" protocol, but after I setup a real server for testing, I found both "http//" and "ws//" will work using the official code.

Everything is fine till now. But soon I found I can't establish a connection using third-party online tester sites like:
1. www.websocket.org/echo.html
2. www.blue-zero.com/WebSocket

The connection seemed never established or closed asap connected,
I found "Firefox can't establish a connection to the server at ws://mytestserver:8888/?encoding=text" in Firefox console,
or "WebSocket connection to 'ws://mytestserver:8888' failed: Connection closed before receiving a handshake response" in Chrome console.

At last I changed socket.io to ws (npm install --save ws). using sample code from github.com/websockets/ws. all tester sites worked well.

(Of course, my final purpose is not to make a tester site work. the fact is the websocket lib based on nopoll integrated in my chip has exactly the same behavior as the tester sites.)

Anybody knows the reason why socket.io does not work with 3rd-party clients while ws does? Thanks a lot.

vdonkey
  • 106
  • 10
  • As I know `ws` use native html-socket without any additional scripts on client side. Other sockets (`socket.io`, `sockjs`, etc) demands client-side scripts. – Aikon Mogwai Jul 31 '16 at 16:35

1 Answers1

1

socket.io requires a socket.io server on the server-side end of things. It will not connect to only a webSocket server.

While socket.io uses webSocket as the underlying transport, it adds a layer on top of webSocket to implement a whole bunch of additional features and that requires server-side support for socket.io. So, you can't connect to a plain webSocket server with the socket.io client.

You must match:

webSocket client <==> webSocket server
socket.io client <==> socket.io server
Community
  • 1
  • 1
jfriend00
  • 683,504
  • 96
  • 985
  • 979