Skip to content

Commit

Permalink
Fix/Remote: Improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
TwinFan committed Jan 20, 2024
1 parent bf452c7 commit 172fddf
Show file tree
Hide file tree
Showing 72 changed files with 3,286 additions and 1,090 deletions.
27 changes: 27 additions & 0 deletions docs/MCrecv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env python3

import socket
import struct
import binascii

MCAST_GRP = '239.255.1.1'
MCAST_PORT = 49788
IS_ALL_GROUPS = True

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
if IS_ALL_GROUPS:
# on this port, receives ALL multicast groups
sock.bind(('', MCAST_PORT))
else:
# on this port, listen ONLY to MCAST_GRP
sock.bind((MCAST_GRP, MCAST_PORT))
mreq = struct.pack("4sl", socket.inet_aton(MCAST_GRP), socket.INADDR_ANY)

sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)

while True:
(b, address) = sock.recvfrom(10240)
print (address)
print (binascii.hexlify(b))
19 changes: 19 additions & 0 deletions docs/MCsend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python3

import socket

MCAST_GRP = '239.255.1.1'
MCAST_PORT = 49788

# 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)
sock.sendto(b"robot", (MCAST_GRP, MCAST_PORT))
44 changes: 37 additions & 7 deletions docs/html/Network_8cpp.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 172fddf

Please sign in to comment.