diff --git a/common/tests/functional/multicast_receiver.py b/common/tests/functional/multicast_receiver.py new file mode 100755 index 000000000..b37f6bd05 --- /dev/null +++ b/common/tests/functional/multicast_receiver.py @@ -0,0 +1,24 @@ +import socket + +# Define multicast address and port +MULTICAST_ADDRESS = "ff12::1" +PORT = 12345 + +# Create a UDP socket +sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) + +# Bind to the port +sock.bind(('', PORT)) + +# Tell the operating system to add the socket to the multicast group +group_bin = socket.inet_pton(socket.AF_INET6, MULTICAST_ADDRESS) +mreq = group_bin + b'\0' * (len(group_bin) - len(group_bin)) +sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_JOIN_GROUP, mreq) + +print("Listening for multicast messages...") + +# Receive/respond loop +while True: + data, address = sock.recvfrom(1024) + print(f"Received message from {address}: {data.decode('utf-8')}") + diff --git a/common/tests/functional/multicast_sender.py b/common/tests/functional/multicast_sender.py new file mode 100755 index 000000000..c98893918 --- /dev/null +++ b/common/tests/functional/multicast_sender.py @@ -0,0 +1,20 @@ +import socket + +# Define multicast address and port +MULTICAST_ADDRESS = "ff12::1" +PORT = 12345 + +# Message to send +MESSAGE = "Hello, multicast world!" + +# Create a UDP socket +sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) + +# Set time-to-live for multicast packet (optional) +sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_HOPS, 1) + +# Send message +sock.sendto(MESSAGE.encode('utf-8'), (MULTICAST_ADDRESS, PORT)) + +print("Message sent.") + diff --git a/common/tests/functional/select.sh b/common/tests/functional/select.sh new file mode 100644 index 000000000..98cb40d84 --- /dev/null +++ b/common/tests/functional/select.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Function to run multicast sender script +run_sender() { + ./multicast_sender.sh +} + +# Function to run multicast receiver script +run_receiver() { + ./multicast_receiver.sh +} + +# Prompt user for selection +echo "Select an option:" +echo "1. Run as Sender" +echo "2. Run as Receiver" +read -p "Enter your choice (1 or 2): " choice + +# Check user's choice and run the appropriate script +case $choice in + 1) run_sender;; + 2) run_receiver;; + *) echo "Invalid choice. Please enter 1 or 2.";; +esac +