0

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?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
rasa911216
  • 97
  • 2
  • 12

1 Answers1

3

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.

nwxnk
  • 91
  • 6
  • Oh I see, was afraid that would be the case. Oh well, thanks a lot for your answer and time! Guess I'll switch to Websockets. – rasa911216 Sep 08 '18 at 22:39