-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
51 lines (39 loc) · 1.06 KB
/
main.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
import socket
import _thread
import pickle
from config import socketIp
def new_client(client, addr, clientID, clients):
while True:
try:
data = pickle.loads(client.recv(2048))
except EOFError:
pass
else:
print(data, " : ", clientID)
if clientID == 1:
c = clients[-1][0]
c.send(pickle.dumps(data))
del clients[-1]
client.close()
def main():
clients = []
clientID = -1
host = socketIp
port = 5500
server = socket.socket()
server.bind((host, port))
server.listen(4)
print("Server started. Listening on port: ", port)
while True:
c, addr = server.accept()
clientID += 1
if clientID != 0:
clients.append((c, addr))
print("Length: ", len(clients))
if clientID == 1:
print("Connected to API: ", addr)
_thread.start_new_thread(new_client, (c, addr, clientID, clients))
server.close()
if __name__ == '__main__':
while True:
main()