Parcourir la source

Adding server

Andrej Studen il y a 3 ans
Parent
commit
a1e11e606a
1 fichiers modifiés avec 19 ajouts et 0 suppressions
  1. 19 0
      websocketServer.py

+ 19 - 0
websocketServer.py

@@ -0,0 +1,19 @@
+import asyncio
+import websockets
+
+async def hello(websocket):
+    name = await websocket.recv()
+    print(f"<<< {name}")
+
+    greeting = f"Hello {name}!"
+
+    #await websocket.send(greeting)
+    #don't send anything, just log
+    print(f">>> {greeting}")
+
+async def main():
+    async with websockets.serve(hello, "193.2.68.227", 8765):
+        await asyncio.Future()  # run forever
+
+if __name__ == "__main__":
+    asyncio.run(main())