Websocket connection failed


I’m trying to set up a little local sandbox to play around with this awesome library. I’m super interested in the websocket capabilities and this snippet that l’d like to try out. I’ve downloaded it local and have it running, but it’s relying on an Yjs’s demo websocket so I’d like to set up my own local websocket. I’ve essentially coped the file format from the ysocket repo and have the local host server running because I’m able to access localhost:1234 on the browser.

However when I try to connect to the socket from the front-end, I get this error:

I can’t really pinpoint this error message. I thought it was a proxy or SSL error initially when reading online but the error seems to suggest it’s related to ysocket so I’m not too sure where to start. I’m super new to websockets so any help wold be appreciated!

Do you get an ok message at http://localhost:1234/? That means the websocket server is at least running and accessible on that port.

yep ok is showing on http://localhost:1234/

I just can’t seem to connect to it via react front end :confused:

For more context, when I click on the error on the web console- it leads me to here:

Are you using the built-in y-websocket server by running HOST=localhost PORT=1234 npx y-websocket?

1 Like

I’ve tried that method and executing the server.js file with npm, they both have the same output

The console does successfully print out: running at ‘localhost’ on port 1234

Alright so it looks like I was trying to connect to wss://localhost:1234 instead of ws://localhost:1234

I didn’t realize that I had to change it since the wss to ws since it was a local instance. Your questions really helped me debug this- thanks!

1 Like

Glad you figured it out!