from sanic import Sanic from sanic.response import html import engineio eio = engineio.AsyncServer(async_mode='sanic') app = Sanic() eio.attach(app) @app.route('/') async def index(request): with open('latency.html') as f: return html(f.read()) @eio.on('message') async def message(sid, data): await eio.send(sid, 'pong', binary=False) app.static('/static', './static') if __name__ == '__main__': app.run()
import os import uvicorn import engineio eio = engineio.AsyncServer(async_mode='asgi') app = engineio.ASGIApp(eio, static_files={ '/': 'simple.html', '/static': 'static', }) @eio.on('connect') def connect(sid, environ): print("connect ", sid) @eio.on('message') async def message(sid, data): print('message from', sid, data) await eio.send(sid, 'Thank you for your message!', binary=False) @eio.on('disconnect') def disconnect(sid): print('disconnect ', sid) if __name__ == '__main__': uvicorn.run(app, host='127.0.0.1', port=5000)
import os import tornado.ioloop from tornado.options import define, options, parse_command_line import tornado.web import engineio define("port", default=8888, help="run on the given port", type=int) define("debug", default=False, help="run in debug mode") eio = engineio.AsyncServer(async_mode='tornado') class MainHandler(tornado.web.RequestHandler): def get(self): self.render("simple.html") @eio.on('connect') def connect(sid, environ): print("connect ", sid) @eio.on('message') async def message(sid, data): print('message from', sid, data) await eio.send(sid, 'Thank you for your message!', binary=False) @eio.on('disconnect')
from aiohttp import web import engineio eio = engineio.AsyncServer(async_mode='aiohttp') app = web.Application() eio.attach(app) async def index(request): with open('latency.html') as f: return web.Response(text=f.read(), content_type='text/html') @eio.on('message') async def message(sid, data): await eio.send(sid, 'pong') app.router.add_static('/static', 'static') app.router.add_get('/', index) if __name__ == '__main__': web.run_app(app)