-
Notifications
You must be signed in to change notification settings - Fork 2
/
studentComm.py
46 lines (26 loc) · 1.05 KB
/
studentComm.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
import socket
import json
import studentcodeEX
# Quick-and-dirty TCP Server:
ss = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ss.bind(('localhost', 6000))
ss.listen(10)
print('Waiting for simulator')
(clientsocket, address) = ss.accept()
def recv_commands():
message = ""
while(1):
messagepart = clientsocket.recv(2048).decode()
message += messagepart
if message[-1] == '\n':
jsonargs = json.loads(messagepart)
message = ""
if(jsonargs["exit"] != 0):
return
#todo: json data sanitization
bitrate = studentcodeEX.student_entrypoint(jsonargs["Measured Bandwidth"], jsonargs["Previous Throughput"], jsonargs["Buffer Occupancy"], jsonargs["Available Bitrates"], jsonargs["Video Time"], jsonargs["Chunk"], jsonargs["Rebuffering Time"], jsonargs["Preferred Bitrate"])
payload = json.dumps({"bitrate" : bitrate}) + '\n'
clientsocket.sendall(payload.encode())
if __name__ == "__main__":
recv_commands()
ss.close()