September 2018
Intermediate to advanced
426 pages
10h 46m
English
The Socket.IO server is available in the official python repository and can be installed via pip: pip install python-socketio.
The full documentation is available at https://python-socketio.readthedocs.io/en/latest/.
The following is an example that works in python 3.5 where we implement a Socket.IO server using the aiohttp framework for asyncio:
from aiohttp import webimport socketiosocket_io = socketio.AsyncServer()app = web.Application()socket_io.attach(app)async def index(request): return web.Response(text='Hello world from socketio' content_type='text/html')# You will receive the new messages and send them by socket@socket_io.on('message')def print_message(sid, message): print("Socket ID: " , sid) ...Read now
Unlock full access