-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcsn_cli_server.py
46 lines (39 loc) · 1.25 KB
/
csn_cli_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
from threading import Thread
import socket
import sys
import csn_server_helper
host = ""
port = 666 # used by the original Doom and by trojans. Should be free.
s = socket.socket() # Create a socket object
s.bind((host, port)) # Bind to the port
global clients
clients = list()
def ListenThread(c,addr):
global clients
isConnected = True
helper = csn_server_helper.ServerHelper(c,addr)
clients.append(helper)
while isConnected:
try:
data = c.recv(1024)
#print(data)
if(len(data)>0):
#print(data)
helper.CheckPacket(data,clients) #process the incoming packet(s)
except:
#print("Unexpected error:", sys.exc_info(), sys.exc_traceback())
try:
clients.remove(helper) #remove client from client list
except:
#print("Unexpected error:", sys.exc_info())
return
try:
clients.remove(helper) #remove client from client list
except:
pass
while True:
#always listen for new connections
s.listen(5)
c, addr = s.accept()
print ('Got connection from', addr)
threadz = Thread(target = ListenThread, args = (c, addr)).start()