Page 1 of 1

Problem polling a UDP socket on ESP8266 -- works on ESP32

Posted: Wed Mar 20, 2019 6:11 pm
by oserror
I am not sure where this post belongs. On the ESP8266, when I try to use select to poll a UDP socket, I am getting POLLHUP? errors:

Code: Select all

>>> import socket, select
>>> sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
>>> sock.bind(('0.0.0.0', 2001))
>>> poller = select.poll()
>>> poller.register(sock, select.POLLIN | select.POLLHUP | select.POLLERR)
>>> while True:
...     sleep(1)
...     print('Waiting for event')
...     events = poller.poll(1000)
...     for s, flag in events:
...         print('socket: %s\tflag: %s' % (s, flag))
...         
...         
... 
Waiting for event
socket: <socket state=0 timeout=-1 incoming=0 off=0>	flag: 16
Waiting for event
socket: <socket state=0 timeout=-1 incoming=0 off=0>	flag: 16
Waiting for event
socket: <socket state=0 timeout=-1 incoming=0 off=0>	flag: 16
Waiting for event
socket: <socket state=0 timeout=-1 incoming=0 off=0>	flag: 16
On the ESP32, things are normal:

Code: Select all

=== import socket, select
=== sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
=== sock.bind(('0.0.0.0', 2001))
=== poller = select.poll()
=== poller.register(sock, select.POLLIN | select.POLLHUP | select.POLLERR)
=== while True:
===     sleep(1)
===     print('Waiting for event')
===     events = poller.poll(1000)
===     for s, flag in events:
===         print('socket: %s\tflag: %s' % (s, flag))

Waiting for event
Waiting for event
Waiting for event
Waiting for event
Waiting for event
Waiting for event
Waiting for event
Is there something missing here that I should be doing? I have changed port numbers and there should not be any traffic at all directed towards the device. TCP sockets work fine on both machines.

Thanks for any help!

Re: Problem polling a UDP socket on ESP8266 -- works on ESP32

Posted: Mon Dec 23, 2019 7:06 pm
by ansonvandoren
Did you ever get an answer to this question? I'm seeing the same thing on ESP8266, where UDP sockets always return select.POLLHUP

Re: Problem polling a UDP socket on ESP8266 -- works on ESP32

Posted: Tue Dec 24, 2019 12:17 am
by oserror
No, I didn't. I ended up using TCP instead.

Maybe someone else can figure it out? I'm stuck.

Re: Problem polling a UDP socket on ESP8266 -- works on ESP32

Posted: Fri Dec 27, 2019 2:52 pm
by ansonvandoren
I just started ignoring the POLLHUP events in the loop, and realized that I'm also getting the actual POLLIN events as well, but they were masked by the flood of POLLHUP.