0
votes

I am trying to connect my client side javascript to a backend websocket service hosted using socket.io .

I am trying to use the native WebSocket object to connect to the socket.io server like :

new WebSocket("wss://localhost:8080/socket.io/websocket")

But I keep getting :

Connection closed before receiving a handshake response

I have tried connecting using the client side socket.io library just to confirm that the server is up and fine, and this works, but in production I only have the WebSocket object available.

Any ideas?

1
Change your url to 'ws://localhost:8080/socket.io/websocket'. Did it work?Tushar Arora
nope it did not workBryan Arbelo - MaG3Stican

1 Answers

0
votes

wss is for secure web socket, I assume you are not using ssl cerificate in localhost so

new WebSocket("ws://localhost:8080/socket.io/websocket")

will work.

Edit: When you use socket.io client, you will be using

var socket = io.connect('http://localhost:8080');

to use url with WebSocket you need ws://localhost:8080/socket.io/?transport=websocket

new WebSocket('ws://localhost:8080/socket.io/?transport=websocket')