From 0cac45809f082f16ec259ab3d26021dd3daed1df Mon Sep 17 00:00:00 2001 From: Jing Su Date: Thu, 9 Mar 2017 18:33:34 +0800 Subject: [PATCH] add blueprints websocket example --- examples/blueprints.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/examples/blueprints.py b/examples/blueprints.py index b8192068..554c9cef 100644 --- a/examples/blueprints.py +++ b/examples/blueprints.py @@ -6,6 +6,7 @@ from sanic.response import json, text app = Sanic(__name__) blueprint = Blueprint('name', url_prefix='/my_blueprint') blueprint2 = Blueprint('name', url_prefix='/my_blueprint2') +blueprint3 = Blueprint('name', url_prefix='/my_blueprint3') @blueprint.route('/foo') @@ -17,8 +18,17 @@ async def foo(request): async def foo2(request): return json({'msg': 'hi from blueprint2'}) +@blueprint3.websocket('/foo') +async def foo3(request, ws): + while True: + data = 'hello!' + print('Sending: ' + data) + await ws.send(data) + data = await ws.recv() + print('Received: ' + data) app.blueprint(blueprint) app.blueprint(blueprint2) +app.blueprint(blueprint3) app.run(host="0.0.0.0", port=8000, debug=True)