import socket # create a UDP socket sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # set the address and port of the remote host ip_address = '127.0.0.1' port = 20810 remote_address = (ip_address, port) # set a timeout of 5 seconds for recvfrom() sock.settimeout(5.0) # send a message to the remote host message = b'\xff\xff\xff\xffgetbots ' sock.sendto(message, remote_address) try: # wait for a response from the remote host response, remote_address = sock.recvfrom(4096) except socket.timeout: # handle timeout print('Timed out while waiting for response.') else: # print the response print('Received: ', response)