-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared_test_secondary.py
More file actions
34 lines (27 loc) · 845 Bytes
/
shared_test_secondary.py
File metadata and controls
34 lines (27 loc) · 845 Bytes
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
import socket
import netifaces as ni
def sendDataPrimary(message):
UDP_IP = ni.ifaddresses('lo')[ni.AF_INET][0]['addr']
UDP_PORT = 10000
MESSAGE = message.encode()
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
def readDataPrimary():
UDP_IP = "127.0.0.1"
UDP_PORT = 5000
try:
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))
except:
pass
while True:
data, addr = sock.recvfrom(1024)
incoming = data.decode()
if incoming:
print("Received")
sendDataPrimary(incoming)
print(f"{incoming} sent")
if __name__ == '__main__':
sendDataPrimary("Secondary")
readDataPrimary()