0

I am very new to web programming and to Flask Socket IO.

I made a fast script to host with flask like this:

from flask import Flask, render_template
from flask_socketio import SocketIO

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)

@app.route('/', methods=['GET', 'POST'])
def index():
    return "hi"

@socketio.on('message')
def handle_message(message):
    print('received message: ' + message)


if __name__ == '__main__':
    socketio.run(app)

And here is the client side:

import requests

session = requests.session() 
a = raw_input()
while a!='stop':
    r = session.post('http://localhost:5000/', data={'message':a})
    #print r.text
    print(r.text)
    a = raw_input()

If I understood well, whenever I post something with the client side, the host should print "received message: mymessage". But unfortunately it doesn't. Could you please help me ? (I just started to learn this).

Thank you

johanDa9u
  • 63
  • 5

1 Answers1

0

You can't use a standard HTTP client such as requests to talk to a Socket.IO server. You need a Socket.IO client instead.

For Python, you can use SocketIO-Client.

Miguel Grinberg
  • 65,299
  • 14
  • 133
  • 152