First code

This commit is contained in:
Lexi / Zoe 2018-10-27 04:36:09 +02:00
parent 1ce94580ff
commit 3587d0184f
4 changed files with 38 additions and 0 deletions

View File

16
public_html/index.html Normal file
View File

@ -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
public_html/js/client.js Normal file
View File

22
server/chatserver.py Executable file
View File

@ -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()