Commit 1f4fcb1c authored by Léo-Paul Géneau's avatar Léo-Paul Géneau 👾

Add client and server scripts to test multicast

parents
import argparse
import socket
import struct
import sys
if not hasattr(socket, 'SO_BINDTODEVICE'):
socket.SO_BINDTODEVICE = 25
parser = argparse.ArgumentParser()
parser.add_argument("multicast_group", help="Multicast IPv6 to use for subscription")
args = parser.parse_args()
server_address = ('', 10000)
sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
sock.bind(server_address)
# on all interfaces.
sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_JOIN_GROUP, socket.inet_pton(socket.AF_INET6, args.multicast_group) + struct.pack('@I', 0))
try:
while True:
data, address = sock.recvfrom(10240)
print(data.decode("utf-8"))
finally:
sock.close()
import argparse
import socket
import struct
import traceback
parser = argparse.ArgumentParser()
parser.add_argument("addr", help="IPv6 address to use for source")
parser.add_argument("multicast_group", help="Multicast IPv6 address to use for destination")
args = parser.parse_args()
print(args.addr)
print(args.multicast_group)
ttl = 12
sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_HOPS, ttl)
sock.bind((args.addr, 10000))
try:
while True:
input_msg = input('msg --> ')
try:
sock.sendto(input_msg.encode("utf-8"), (args.multicast_group, 10000))
except Exception:
traceback.print_exc()
continue
finally:
sock.close()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment