Skip to content

Instantly share code, notes, and snippets.

Created March 23, 2018 15:27
What would you like to do?
test websockets server in python3
#!/usr/bin/env python
# test websockets - requires python 3.6+ & sanic
# start server & hit http://localhost:8000/static/WebSockets.html
# Put ws://localhost:8000/feed as Target
from sanic import Sanic
app = Sanic()
# create static dir & put
app.static('/static', './static')
async def feed(request, ws):
while True:
data = 'hello!'
print('Sending: ' + data)
await ws.send(data)
data = await ws.recv()
print('Received: ' + data)
if __name__ == "__main__":"", port=8000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment