-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
61 lines (50 loc) · 1.53 KB
/
Copy pathmain.py
File metadata and controls
61 lines (50 loc) · 1.53 KB
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
61
from stream.stream import Stream
import threading
import socket
import json
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
port = 4000
adress = '0.0.0.0'
def connectionThread(conn):
# production only
control = Stream()
msg_recv = conn.recv(1024)
msg_recv = msg_recv.decode('utf8')
msgEncoded = json.loads(msg_recv)
stream_key = msgEncoded['key']
success = False
message = 'unknown error'
if stream_key != '':
if (msgEncoded['control'] == 'start'):
success = control.startStream(stream_key)
if success:
message = 'stream should be started'
else:
message = 'something went wrong.'
elif (msgEncoded['control'] == 'stop'):
success = control.stopstream(stream_key)
if success:
message = 'stream should be stopped'
else:
message = 'something went wrong.'
else:
message = 'stream key was not set'
success = False
print(msg_recv)
data = {
'successful': success,
'message': message,
}
msgSend = json.dumps(data)
conn.send(msgSend.encode())
conn.close()
if __name__ == '__main__':
connection.bind((adress, port))
connection.listen(10)
print('Server listening on', adress + ':' + str(port))
while True:
conn, addr = connection.accept()
print('Got connection')
t = threading.Thread(target=connectionThread, args=[conn, ])
t.daemon = True
t.start()