So basically I want to create a Websocket server using Python, on my last question about this I said I didn't want to use external libraries, but that wasn't received very well. So how can you do it using external libraries? I have already figured out the Websocket send using Javascript, but I need a Python Websocket server. So can someone give me a working example with Python 3.6?
So basically I want to create a Websocket server using Python, on my last question about this I said I didn't want to use external libraries, but that wasn't received very well. So how can you do it using external libraries? I have already figured out the Websocket send using Javascript, but I need a Python Websocket server. So can someone give me a working example with Python 3.6?
Share Improve this question asked Jul 10, 2017 at 1:06 user7873306user78733061 Answer
Reset to default 5the following es from https://websockets.readthedocs.io/en/stable/intro.html ... which was the second link i think i found when i googled "python3 websockets"
#!/usr/bin/env python
import asyncio
import websockets
async def hello(websocket, path):
name = await websocket.recv()
print("< {}".format(name))
greeting = "Hello {}!".format(name)
await websocket.send(greeting)
print("> {}".format(greeting))
start_server = websockets.serve(hello, 'localhost', 8765)
asyncio.get_event_loop().run_until_plete(start_server)
asyncio.get_event_loop().run_forever()