-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.py
60 lines (48 loc) · 1.7 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from queue import Queue
from QUIC_Server import quicconnectserver
import ParserServer
import time
import sys
import threading
def processing(server,data_queue):
time_start = time.time()
while True:
if data_queue and time.time() - time_start < 10:
frame = data_queue.get()
t2 = time.time()
if ( frame["time_taken"] + (t2 - frame["t1"]) < 0.15):
#print("frame ",frame["id"]," processing")
time.sleep(0.03)
server_reply = frame["id"] + "processed"
server.quic_obj.server_send(server_reply)
time_start = time.time()
else:
#print("frame ",frame["id"]," dropped")
server_reply = frame["id"] + "dropped"
server.quic_obj.server_send(server_reply)
def main():
#print("entered server code")
print("frame,time,offset,recv time")
args = ParserServer.parse("Parse server args")
data_queue = Queue()
j = quicconnectserver(args.host,args.port,args.certificate, args.private_key,args.verbose)
prc_thread = threading.Thread(target=processing,args=(j,data_queue))
prc_thread.start()
counter = 0
while True:
id,f,t,o,r=j.quic_obj.recieve()
if id:
temp = dict()
temp["frame"] = f
temp["time_taken"] = t
temp["t1"] = time.time()
temp["id"] = id
print(id,",",t,",",o,",",r)
#print("time",t)
data_queue.put(temp)
else:
if counter > 10:
exit()
counter+=1
if __name__ == "__main__":
main()