This commit is contained in:
2024-04-24 13:28:38 -04:00
commit 45ac4648dd
24 changed files with 1218 additions and 0 deletions

22
old/udp_server.py Normal file
View File

@@ -0,0 +1,22 @@
import socket
MCAST_GRP = '239.255.255.255'
MCAST_PORT = 5007
# regarding socket.IP_MULTICAST_TTL
# ---------------------------------
# for all packets sent, after two hops on the network the packet will not
# be re-sent/broadcast (see https://www.tldp.org/HOWTO/Multicast-HOWTO-6.html)
MULTICAST_TTL = 2
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, MULTICAST_TTL)
# For Python 3, change next line to 'sock.sendto(b"robot", ...' to avoid the
# "bytes-like object is required" msg (https://stackoverflow.com/a/42612820)
from datetime import datetime
import time
for i in range(100):
dsend = str(i)+' '+str(datetime.now())
sock.sendto(dsend.encode(), (MCAST_GRP, MCAST_PORT))