-1

After doing some digging, I've been trying to connect Flask Socketio with a websocket in JS by doing


socket = new Websocket("ws://localhost:5000")

But this wont work, I know that there is another way with Socket.io's own library, but is there any way I can do it like this? Thanks!

Artrix
  • 149
  • 10

1 Answers1

0

No. WebSocket is a different protocol than Socket.IO. If you use a WebSocket client, then you have to use a WebSocket server. If your server does Socket.IO, then you must use Socket.IO for the client as well.

The confusion probably comes from the fact that Socket.IO builds on top of WebSocket, but it uses a specific protocol that normal WebSocket clients do not understand.

Miguel Grinberg
  • 65,299
  • 14
  • 133
  • 152
  • Is there any Websocket servers for flask? – Artrix May 11 '20 at 00:50
  • Flask does not support WebSocket. The question that you want to ask is if there are any WSGI servers that *also* support WebSocket. There are a few of them, eventlet and uwsgi come to mind. Also gevent with the gevent-websocket add-on. – Miguel Grinberg May 11 '20 at 09:52