rasa911216
rasa911216

Reputation: 97

Connecting to Flask SocketIO implementation

I'm having some issues trying to connect to a Flask SocketIO implementation. I followed the examples and set up a server with the following code:

from flask_socketio import SocketIO, send

application = Flask(__name__)
socketio = SocketIO(application)

@socketio.on('message')
def doStuff(msg):
    print(msg)

if __name__=="__main__":
  socketio.run(application, port=8080)

and a client in Python:

import websocket
from websocket import create_connection

ws = create_connection("ws://SERVER_IP:8080/")
print(ws)

print("Sending 'Hello, World'...")
ws.send("Hello, World")
print("Sent")

print("Receiving...")
result =  ws.recv()
print("Received '%s'" % result)
ws.close()

Nonetheless when I try to connect, I get WebSocketBadStatusException: Handshake status 200 OK. All the examples I've seen of connection to SocketIO involve having a static page with javascript but I want to use this as a Desktop application or use it with Kotlin.

What am I missing?

Upvotes: 0

Views: 6264

Answers (1)

nwxnk
nwxnk

Reputation: 101

Flask-SocketIO is not a WebSocket server, it is a Socket.IO server. The client that you need to use needs to understand the Socket.IO protocol, a WebSocket client alone is not enough. reference

Check this question.

Upvotes: 3

Related Questions