-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtracker.py
48 lines (35 loc) · 1.04 KB
/
tracker.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
import funcs
import threading
import queue
from config import HOST, PORT
send_lock = threading.Lock()
send_queues = []
def client_receive(client_socket,client_address,q):
print("connected to " + str(client_socket) + " " )
with send_lock:
send_queues.append(q)
th = threading.Thread(target = send_to_client,args = [client_socket,q],daemon = True)
th.start()
while True:
print("trying to receive")
size = funcs.receive_data(client_socket,5)
message = funcs.receive_data(client_socket,int(size))
with send_lock:
for qu in send_queues:
qu.put(size+message)
def send_to_client(sock,q):
while True:
data = q.get()
if data == None:
break
send(sock,data)
def send(sock,data):
funcs.send_data(sock,data)
if __name__ == '__main__':
listening_socket = funcs.create_listening_socket(HOST,PORT,100)
while True:
print("Waiting")
client_socket,client_address = listening_socket.accept()
q = queue.Queue()
th = threading.Thread(target = client_receive, args = [client_socket,client_address,q], daemon = True)
th.start()