I would like to create around 10,000 clients and use them to send and recieve messages from Flask-Socketio server. I am using the default Flask Werkzeug development web server.
This is the app.py
from flask import Flask, render_template
from flask_socketio import SocketIO
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)
@socketio.on('message')
def handle_message(message):
print(message)
if __name__ == '__main__':
socketio.run(app,debug=True)
This is the test_client.py
import socketio
from multiprocessing.pool import ThreadPool
# standard Python
sio = socketio.Client()
def f(thread):
server = 'http://127.0.0.1:5000/' + str(thread)
s = f'/{thread}'
sio.connect(server)
sio.emit('message', {'Hello': i}, namespace=s)
threads = 5
t = ThreadPool(threads)
t.map(f, range(0, threads))
Current test_client.py's Terminal Output:
raise exceptions.BadNamespaceError(
socketio.exceptions.BadNamespaceError: /2 is not a connected namespace.
Expected app.py's Terminal Output:
Hello: 0
Hello: 1
Hello: 2
Hello: 3
Hello: 4
Please if there is a different/ better way of doing this, send me the doc link to check.