Jan-28-2024, 11:03 PM
Do you have a network connection on your computer configured to have a static IP address on the 192.168.0 subnet? sock.sendto() quietly fails if it cannot send or nobody is listening. You don't know if the message was received until you get back a response, and your program is not getting a response.
If you want a smaller program to test with, this program just sends the MAC command and reads the response:
If you want a smaller program to test with, this program just sends the MAC command and reads the response:
import socket def empty_read_buffer(sock): try: while True: sock.recv(4096) except TimeoutError: pass IP = '192.168.0.168' PORT = 50000 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.settimeout(0.2) empty_read_buffer(sock) msg = b'MAC' + bytes([0]*29) for _ in range(5): sock.sendto(msg, (IP, PORT)) try: reply = sock.recv(32) print(reply) if reply and reply[:3] == msg[:3]: break except TimeoutError: pass else: print("Failed to read response.")