Why did HTML WebSocket access fail to start on Socket.io server?

As socket.io said, it supports WebSocket, so I am using the standard HTML5 web socket api to access the socket.io server, but I always get below error:

WebSocket connection with 'ws: // localhost: 8080 /' failed: Connection closed before receiving handshake response

Then I tried to use socket.io client in js to access socket.io server, it works and thanks to chrome network monitoring I found it correctly using websocket protocol.

Has anyone ever tried W3C Websocket api to access socket.io server and faced similar problem? or any ideas or clues for my problem? appreciated!

Test code here: https://github.com/piginzoo/socketiotest

+3


source to share


2 answers


We had exactly the same problem. Completed with ws websites. Not sure if there is a better solution.



0


source


Note. Socket.IO is not a WebSocket implementation. While Socket.IO does use WebSocket as its transport whenever possible, it adds some metadata to each package: the package type, namespace, and ack id when a message acknowledgment is required. This is why the WebSocket client will not be able to successfully connect to the Socket.IO server and the Socket.IO client will not be able to connect to the WebSocket server (for example ws: //echo.websocket.org).
And I find this in socketio github issues:
Socket.IO is not a WebSocket server. Please see ws . https://github.com/socketio/socket.io/issues/3022



0


source







All Articles