-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
62 lines (51 loc) · 1.51 KB
/
client.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
61
62
import socket
import threading
import pickle
import runtimeREF
TCP_PORT = 6969
ip_range = '.'.join(runtimeREF.HOSTIP.split('.')[0:3]) + '.'
connection = None
threads = []
def send(arg):
connection.send(pickle.dumps(arg))
def onConnect(arg):
threading.Thread(target=runtimeREF.fnDir[52], args=(arg,)).start()
threading.Thread(target=runtimeREF.updateClients, args=(arg,)).start()
def connect(ip_address):
global connection
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1)
s.connect((ip_address, TCP_PORT))
connection = s
connection.settimeout(None)
print(f"TCP Server at {ip_address}:{TCP_PORT}")
except:
s.close()
pass
def getServer():
for i in range(1, 256):
ip_address = ip_range + str(i)
thread = threading.Thread(target=connect, args=(ip_address,))
thread.start()
threads.append(thread)
for thread in threads:
thread.join()
if (connection == None):
return False
return True
if __name__ == "__main__":
if (getServer()):
send("UwU")
while True:
try:
data = connection.recv(1024)
except ConnectionResetError:
print("disconnected")
break
if not data:
print("disconnected")
break
# unpickling after checks to prevent error `EOFError: Ran out of input`
data = pickle.loads(data)
print(data)