Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add multicast files #413

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions common/tests/functional/multicast_receiver.py
Original file line number Diff line number Diff line change
@@ -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')}")

20 changes: 20 additions & 0 deletions common/tests/functional/multicast_sender.py
Original file line number Diff line number Diff line change
@@ -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.")

25 changes: 25 additions & 0 deletions common/tests/functional/select.sh
Original file line number Diff line number Diff line change
@@ -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

Loading