-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask.py
executable file
·72 lines (30 loc) · 973 Bytes
/
task.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
44
45
46
47
48
49
50
51
52
53
54
55
# coding utf-8
from phone_book.phone_book_view_controller import PhoneBookViewController
from phone_book.phone_book_view_controller_network import PhoneBookViewControllerNet
import phone_book.settings
import socket
import threading
is_finished = False
def handle(c):
while not is_finished:
controller = PhoneBookViewControllerNet()
choice = phone_book.settings.DEFAULT_CHOICE
controller.set_socket(c)
while choice != phone_book.settings.EXIT:
choice = controller.print_menu()
controller.start_action(choice)
controller.print_to_socket('Good bye! :)')
c.close()
break
s = socket.socket()
s.bind(('0.0.0.0', 8000))
s.listen(5)
print "Server started"
try:
while True:
c, a = s.accept()
print "Connected", a
t = threading.Thread(target=handle, args=(c, ))
t.start()
except KeyboardInterrupt:
is_finished = True