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

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
User avatar
oserror
Posts: 39
Joined: Tue Feb 12, 2019 12:26 am

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

Post by oserror » Wed Mar 20, 2019 6:11 pm

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!

ansonvandoren
Posts: 2
Joined: Mon Dec 23, 2019 7:04 pm

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

Post by ansonvandoren » Mon Dec 23, 2019 7:06 pm

Did you ever get an answer to this question? I'm seeing the same thing on ESP8266, where UDP sockets always return select.POLLHUP

User avatar
oserror
Posts: 39
Joined: Tue Feb 12, 2019 12:26 am

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

Post by oserror » Tue Dec 24, 2019 12:17 am

No, I didn't. I ended up using TCP instead.

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

ansonvandoren
Posts: 2
Joined: Mon Dec 23, 2019 7:04 pm

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

Post by ansonvandoren » Fri Dec 27, 2019 2:52 pm

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.

Post Reply