-
Notifications
You must be signed in to change notification settings - Fork 428
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
UDP: setsockopt REUSEADDR suport, when we run process_udp #925
Comments
what behavior would you consider correct? duplicating the packet to the two sockets? Is this what Linux does? Also, I'm curious: What's the use case for binding 2 sockets to the same addr? |
Yeah, I think the correct behavior is packet will be duplicated to the two sockets related doc, and I'm just verify this behavior as follows: import socket
import threading
import time
MULTICAST_ADDR = '239.255.0.1'
PORT = 12345
def send_broadcast_message():
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
message = "Hello, world!"
sock.sendto(message.encode(), ('239.255.0.1', 12345))
print("Sent broadcast message: {}".format(message))
sock.close()
def receive_broadcast_message():
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
mreq = socket.inet_aton(MULTICAST_ADDR) + socket.inet_aton('127.0.0.1')
sock.setsockopt(socket.SOL_IP, socket.IP_ADD_MEMBERSHIP, mreq)
sock.bind(('239.255.0.1', 12345))
data, addr = sock.recvfrom(1024)
print("Received from {}: {}".format(addr, data.decode()))
sock.close()
receive_thread1 = threading.Thread(target=receive_broadcast_message)
receive_thread1.daemon = True
receive_thread1.start()
receive_thread2 = threading.Thread(target=receive_broadcast_message)
receive_thread2.daemon = True
receive_thread2.start()
time.sleep(1)
send_thread = threading.Thread(target=send_broadcast_message)
send_thread.daemon = True
send_thread.start()
send_thread.join()
receive_thread1.join()
receive_thread2.join() Background I'm also glad to receive your reply ✨ |
when we run process_udp, if there are two sockets that bind under the same Ipaddr, one of them will be ignored here
Is it possible to iterate over all udp here and then return? I'm also happy to contribute pr to this great repo.
The text was updated successfully, but these errors were encountered: