Skip to content

UDP Query keeps timing out #9347

Sep 18, 2022 · 6 comments · 4 replies
Discussion options

You must be logged in to vote

Ok, I vaguely remember reading in the docs that asyncio using UDP is flaky or not implemented and has to be handled with polling.

The following code works every time on the first attempt

def configuretime(tzoffset=0):
    NTP_QUERY = bytearray(48)
    NTP_QUERY[0] = 0x1b
    poller = select.poll()

    addr = socket.getaddrinfo(host, 123)[0][-1]
    print(addr)
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.setblocking(False)
    poller.register(s, select.POLLIN)
#    s.settimeout(0)

    res = s.sendto(NTP_QUERY, addr)
    for response in poller.ipoll(300):
        msg = s.recv(48)
        s.close()
        t = struct.unpack("!I", msg[40:44])[0]
        t -= referencetime…

Replies: 6 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@davefes
Comment options

@krishnak
Comment options

@krishnak
Comment options

@krishnak
Comment options

Answer selected by krishnak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants