Home > Net >  Golang socket io unable to establish websocket connection
Golang socket io unable to establish websocket connection

Time:06-17

this is my socket io Go server, basically following the enter image description here

I wasn't able to solve the issue. Any help would be appreciated, thank you!

CodePudding user response:

You are using version 4.5.0 of the client along with (I assume - minimal reproducable examples please) github.com/googollee/go-socket.io. The go package readme states:

Current this library supports 1.4 version of the Socket.IO client. It supports room, namespaces and broadcast at now.

The socket io docs provide a compatibility chart showing that v1 of the server is only supported by version 1 of the client. So the following appears to work (playground - note I also made subtle changes so the message is output):

<script src="https://cdn.socket.io/socket.io-1.7.4.min.js"></script>
<script>
  const socket = io("http://localhost:8000");
  socket.emit("msg", "abc");
</script>

To use a later version of Socket.IO you will need a server that supports a later version of the protocol. gosf appears to support v2 but I have not tried it.

  • Related