-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimpleServer.py
More file actions
42 lines (34 loc) · 939 Bytes
/
Copy pathsimpleServer.py
File metadata and controls
42 lines (34 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import asyncio
import websockets
from remotePlayer import player
from game import game
import threading
async def handler(websocket):
if len(players) > 3:
return
else:
play = player(websocket)
players.append(play)
print(len(players))
if len(players) == 3:
t = threading.Thread(target=startGame)
t.start()
while True:
result = await websocket.recv()
play.result.put(result)
play.event.set()
def startGame():
theGame = game(players=players)
theGame.start()
async def main():
async with websockets.serve(handler, "127.0.0.1", 9999):
await asyncio.Future() # run forever
if __name__ == "__main__":
global players
players = []
global task
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
task = asyncio.get_event_loop().create_task(main())
print('running')
loop.run_until_complete(task)