pythonasyncioeventletgeventlong-pollinglow-latencysocket-iosocketiosocketio-serverweb-serverwebsocket
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
694 B
43 lines
694 B
#! /usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
@author: xuyaoqiang
|
|
@contact: [email protected]
|
|
@date: 2017-07-28 15:29
|
|
@version: 0.0.0
|
|
@license:
|
|
@copyright:
|
|
|
|
"""
|
|
|
|
from sanic import Sanic
|
|
from sanic.response import html
|
|
import socketio
|
|
|
|
|
|
sio = socketio.AsyncServer(async_mode='sanic')
|
|
app = Sanic()
|
|
sio.attach(app)
|
|
|
|
|
|
class TestNamespace(socketio.AsyncNamespace):
|
|
|
|
def on_connect(self, sid, environ):
|
|
pass
|
|
|
|
def on_disconnect(self, sid):
|
|
pass
|
|
|
|
|
|
@app.route('/')
|
|
async def index(request):
|
|
with open('index.html') as f:
|
|
return html(f.read())
|
|
|
|
|
|
sio.register_namespace(TestNamespace('/test'))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app.run(port=8001, debug=True)
|
|
|
|
|