First code
This commit is contained in:
parent
1ce94580ff
commit
3587d0184f
|
|
@ -0,0 +1,16 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>InstantChat</title>
|
||||||
|
<link rel="stylesheet" href="css/style.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<h1>InstantChat</h1>
|
||||||
|
|
||||||
|
<script src="js/client.js"></script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
# Example code from:
|
||||||
|
# https://websockets.readthedocs.io/en/stable/intro.html
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
import websockets
|
||||||
|
|
||||||
|
|
||||||
|
async def hello(websocket, path):
|
||||||
|
name = await websocket.recv()
|
||||||
|
print(f"< {name}")
|
||||||
|
|
||||||
|
greeting = f"Hello {name}!"
|
||||||
|
|
||||||
|
await websocket.send(greeting)
|
||||||
|
print(f"> {greeting}")
|
||||||
|
|
||||||
|
start_server = websockets.serve(hello, 'localhost', 8765)
|
||||||
|
|
||||||
|
asyncio.get_event_loop().run_until_complete(start_server)
|
||||||
|
asyncio.get_event_loop().run_forever()
|
||||||
Loading…
Reference in New Issue