-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.py
More file actions
49 lines (29 loc) · 1.39 KB
/
Copy pathserver.py
File metadata and controls
49 lines (29 loc) · 1.39 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
import socket
server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_socket.bind(('', 12000))
conn_dict = {}
while True:
try:
message, address = server_socket.recvfrom(1024)
message = message.decode("utf-8")
conn_dict[address[0]] = address[1]
if message == "pulse\0":
print("Heartbeat from: {}".format(address))
else:
print("{}:{} is requesting a connection to {}".format(address[0], address[1], message))
ipLookUp = message;
if ipLookUp in conn_dict.keys():
# server_socket.sendto(bytearray(str(7777), "utf-8"), address)
puncherAddress = list(address)
puncherAddress[1] = str(puncherAddress[1])
puncherAddress = ":".join(puncherAddress)
puncherAddress += '\0'
puncheAddress = (ipLookUp, int(conn_dict[ipLookUp]))
print("Telling {} that {} wants to punch them.".format(puncheAddress, puncherAddress))
server_socket.sendto(bytearray(puncherAddress, "utf-8"), puncheAddress)
print("resolved it")
else:
server_socket.sendto(b'404', address)
print("I could not resolve this")
except socket.timeout:
print("Waiting for connection")