-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
43 lines (36 loc) · 1.18 KB
/
server.py
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
43
import socket
import threading
import json
import winsound
import time
from router import Router
# found thread for process
def tread(client, name):
router = Router('maps.txt')
start, end = tuple(json.loads(client.recv(1024)))
best_direction = router.find_shortest_path(start, end)
client.send(name.encode())
client.send("maps.txt".encode())
client.send(f'{best_direction}'.encode())
client.close()
# play sound for active and disable server
def load_sound(address):
winsound.PlaySound(address, winsound.SND_FILENAME)
# found socket for server with id and port appoint
soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
id, port = "127.0.0.1", 72
soc.bind((id, port))
soc.listen(10)
# print and sound for active server
print("started server\nwaiting for connect clients......")
load_sound("sound/active.wav")
# listen to ten client for give answer
for number in range(1, 11):
client, address = soc.accept()
name = f'client {number}'
threading.Thread(target=tread, args=(client, name)).start()
print(f"\nconnection {name} to server .")
print("\nThe server was disabled")
soc.close()
time.sleep(5)
load_sound('sound/end.wav')