You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromflaskimportFlaskfromflask_socketioimportSocketIO, emitimportlogginglogging.basicConfig(level=logging.INFO)
# Create Flask appapp=Flask(__name__)
app.config['SECRET_KEY'] ='test_secret'# Initialize SocketIOsocketio=SocketIO(app, cors_allowed_origins="*",async_mode="gevent")
@app.route("/data_transmission_socket/version", methods=["GET", "POST"])defversionPrint():
return"%s"%"dev-socket-http-req"# Test event for connection health check@socketio.on('ping')defhandle_ping(data):
logging.info('Server Pinged')
# You can log or process the data received from the client (optional)logging.info(f"Received data: {data}")
emit('pong', {'status': 'OK'})
# Handle client connection@socketio.on('connect')defon_connect():
logging.info('Client connected')
emit('connected', {'message': 'Connection established'})
# Handle client disconnection@socketio.on('disconnect')defon_disconnect():
logging.info('Client disconnected')
print("Client disconnected")
# Only run the app if executed directly (used in development only)if__name__=='__main__':
socketio.run(app, port=5000)