socketio plus json

We’ll use Socket.IO to take JSON-RPC requests. It should respond to “ping” with “pong”.

Install Flask, Flask-SocketIO and eventlet to take requests and jsonrpcserver to process them:

$ pip install flask flask-socketio eventlet jsonrpcserver

Create a

from flask import Flask
from flask_socketio import SocketIO, send
from jsonrpcserver import method, dispatch

app = Flask(__name__)
socketio = SocketIO(app)

def ping():
    return "pong"

def handle_message(request):
    response = dispatch(request)
    if response.wanted:
        send(response, json=True)

if __name__ == "__main__":, port=5000)

Start the server:

$ python
(27985) wsgi starting up on