I have written a small Python program that needs to continuously listen on port 2237.
The packets are received from one program, which I will call P1. There is also another program, P2, that receives commands from P1. Both P1 and P2 use port 2237.
My problem is that when I start my Python script, it successfully receives data from P1, but it fails to receive data from P2. The functionality only works again after I stop my program.
The Python script for receiving the packets is:
def run(udp_port: int): logger.info("Starting listener on port %d", udp_port) client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) client.setsockopt()
client.bind(("", udp_port))
while True:
data, addr = client.recvfrom(4096)
src_ip, src_port = addr
logger.debug("Received %d bytes from %s:%d", len(data), src_ip, src_port)
hexdump(data, logging.DEBUG)
try:
payload = parse_message(data)
if payload is not None:
logger.info("%r", payload)
except Exception as e:
logger.error("Failed to parse header: %s", e)
Does anyone know what the root cause of this issue is, and how we can fix it?
In Extra-ordinary Networking you’ll find a link to Broadcasts and Multicasts, Hints and Tips which has specific advice on how to tackle problems like this. I wrote it for folks creating native code, but much of the same advice applies to Python as well. I encourage you to review it and apply the techniques it suggests.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"