Can't connect to my Websocketserver

Hi everyone,
I’m trying to make a websocketserver in python on replit.

Here’s my code :

import asyncio
import websockets
import json 
import os

PORT = 8060

async def handler(websocket, path):
    print("New connection")
    data = await websocket.recv()
    parsedData = json.loads(data)
    print(parsedData)

async def main():
    async with websockets.serve(handler,"0.0.0.0",PORT):
        await asyncio.Future()  # garde le serveur ouvert indéfiniment

asyncio.run(main())

Normally, it should work because the preview starts (as soon as a port is open) and i get that message :

Failed to open a WebSocket connection: empty Connection header.
You cannot access a WebSocket server directly with a browser. You need a WebSocket >client.

I have tried to connect with these urls:

  • wss://projet-5.maxmlr1.repl.co
  • wss://projet-5.maxmlr1.repl.co:8060
  • ws://projet-5.maxmlr1.repl.co
  • ws://projet-5.maxmlr1.repl.co:8060

It’s not working …

Could someone help me ?
Thank you

Click Tools > Settings > Automatically open Webview when a port is open > disabled

2 Likes

How did you try connecting? You can’t go to them in your browser, you need to use JS or another python script,

1 Like

The issue is not about that

I tried in js with :

const client = new Websocket(link)
2 Likes

Did it not work? What errors did you get (JS side).
Can you also link your repl?

1 Like

I just had a sort of timeout message at the end of 30s a failure message.

Here’s the link :
https://replit.com/@MaxMlr1/Projet5#main.py

Is your server running? Did you send any messages to the ws to test?

Did you try this URL with JS?

1 Like

hey there, could you post the js client you’re using

I think they are just using native WS lib.

oh I see, I popped some similar code in and connected via wss://url and it connected just fine, no stalling

1 Like

Yeah I m using the native one

3 Likes

What’s the difference with the code ?

2 Likes

Nothing really… It was just a diff project with same base code

What is link? Try wss

I think the implication might be that they tried replacing link with all four links referenced in the original post?

1 Like

not sure whether it’s a typo, nor where you’re getting this error, but it’s WebSocket, not Websocket.

That link worked for 10min but it’s not anymore. It’s so random