Skip to content

Instantly share code, notes, and snippets.

@Hunter87ff
Created June 8, 2024 12:30
Show Gist options
  • Select an option

  • Save Hunter87ff/b79ae41ab6eb3fd916096089cc3fe3de to your computer and use it in GitHub Desktop.

Select an option

Save Hunter87ff/b79ae41ab6eb3fd916096089cc3fe3de to your computer and use it in GitHub Desktop.
Basic socketio server and client
import socketio
sio = socketio.Client(reconnection=True)
@sio.event
def connect():
print("Connected to the server")
sio.send("Hello world!")
@sio.event
def message(data):
print(f"Received message: {data}")
@sio.event
def disconnect():
print("Disconnected from server")
sio.connect("http://localhost:5000")
sio.wait()
from flask import Flask
from flask_socketio import SocketIO, send
app = Flask(__name__)
socketio = SocketIO(app)
@socketio.on('message')
def handle_message(msg):
print('Message received: ' + msg)
send(msg)
socketio.run(app, debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment