socketio doesn't work anymore #2003
-
I am trying to transform my socketIO project into a blueprint to merge it into a larger project. Before I transform it, the server works well, but after I transformed it following the Flask-SocketIO-Chat, it doesn't work anymore. The server can still run and accept the request from client and return a success code
My code: # -----------------main.py-----------------
from FlaskServer import create_app, socketio
app = create_app(debug=True)
if __name__ == '__main__':
socketio.run(app, port=5000)
# -----------------FlaskServer/__init__.py-----------------
from flask import Flask
from flask_socketio import SocketIO
socketio = SocketIO()
def create_app(debug=True):
"""Create an application."""
app = Flask(__name__)
app.debug = debug
# app.config['SECRET_KEY'] = 'secret!'
from .CameraApp import camera_app
app.register_blueprint(camera_app)
socketio.init_app(app, cors_allowed_origins='*')
return app
# -----------------FlaskServer/CameraApp/__init__.py-----------------
from flask import Blueprint
from . import PylonCamera
camera_app = Blueprint('camera_app', __name__, url_prefix='/camera')
camera = PylonCamera.PylonCamera()
from . import routes
# -----------------FlaskServer/CameraApp/routes.py-----------------
from . import camera
from .. import socketio
@socketio.on('connect')
def connect():
# doesn't excute when client ask for connect but the server returns 200
camera.init_cap()
print(f'client {request.remote_addr}:{request.environ.get("REMOTE_PORT")} connect')
... When JS client trying to connect, server console print this: (3784) wsgi starting up on http://127.0.0.1:5000
(3784) accepted ('127.0.0.1', 60458)
127.0.0.1 - - [07/Aug/2023 14:41:41] "GET /socket.io/?EIO=4&transport=polling&t=OdEkkGd HTTP/1.1" 200 330 0.000000
(3784) accepted ('127.0.0.1', 60459)
127.0.0.1 - - [07/Aug/2023 14:41:41] "POST /socket.io/?EIO=4&transport=polling&t=OdEkkGk&sid=YN1wxQ82Omwxol3IAAAA HTTP/1.1" 200 219 0.000000
(3784) accepted ('127.0.0.1', 60460)
127.0.0.1 - - [07/Aug/2023 14:41:41] "GET /socket.io/?EIO=4&transport=polling&t=OdEkkGl&sid=YN1wxQ82Omwxol3IAAAA HTTP/1.1" 200 233 0.000000
127.0.0.1 - - [07/Aug/2023 14:41:41] "GET /socket.io/?EIO=4&transport=websocket&sid=YN1wxQ82Omwxol3IAAAA HTTP/1.1" 200 0 0.004982 And JS client(
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Socket.IO does not use any Flask routes, so it makes no sense to create a blueprint for it. I suggest you remove the |
Beta Was this translation helpful? Give feedback.
Socket.IO does not use any Flask routes, so it makes no sense to create a blueprint for it. I suggest you remove the
/camera
path from the connection URL in the client, that is how you specify a Socket.IO namespace and has nothing to do with any routes you define in your Flask application or in any blueprints.