Skip to content

UDP native socket server reply not received by client #4445

Closed
@anecdata

Description

@anecdata

Firmware

Adafruit CircuitPython 6.2.0-beta.4 on 2021-03-18; FeatherS2 with ESP32S2  # also tested on beta.2

Code/REPL

CircuitPython native UDP Server code & CPython UDP Client code are in the comments below.

Behavior

I've been testing cross-compatibility of CPython, CircuitPython ESP32SPI, and CircuitPython ESP32-S2 sockets, both TCP and UDP. All supported combinations work except CircuitPython ESP32-S2 UDP Server... none of the three types of clients receive the server's reply to the client-initiated message. It seems to be related to the port number.

TCP

For comparison, let's look first at the working TCP case. Notice in the CircuitPython TCP Server output below that the server accepts a connection from a remote (IP, PORT), receives data from the client, then echoes it back to the client.

CircuitPython TCP Server output:

code.py output:
Connecting to Wifi
Self IP 192.168.6.198
Server ping 192.168.6.198 0.0 ms
Create TCP Server socket ('192.168.6.198', 5010)
Listening
Accepting connections
Accepted from ('192.168.5.32', 51687)
Received packet bytearray(b'Hello, world') 12 bytes from ('192.168.5.32', 51687)
Sent bytearray(b'Hello, world') 12 bytes to ('192.168.5.32', 51687)

TCP Client output (any of the three types):

Create TCP Client Socket
Connecting
Sent 12 bytes
Received b'Hello, world'

Checking the tcpdump view of the transaction, we see that the client outgoing port (59337) does not match the CircuitPython-server-printed port (51687), BUT the dump shows the reply going back to the proper originating port. It works..

16:20:53.930013 IP: (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 64, bad cksum 0 (->ad81)!)
    192.168.5.32.59337 > 192.168.6.198.5010: Flags [S], cksum 0x8d69 (incorrect -> 0xe628), seq 956746751, win 65535, options [mss 1460,nop,wscale 6,nop,nop,TS val 678730438 ecr 0,sackOK,eol], length 0
16:20:54.015444 IP: (tos 0x0, ttl 255, id 56508, offset 0, flags [none], proto TCP (6), length 44)
    192.168.6.198.5010 > 192.168.5.32.59337: Flags [S.], cksum 0xee99 (correct), seq 9048109, ack 956746752, win 2880, options [mss 1440], length 0
...

UDP

Notice in the CircuitPython UDP Server output below that the server (waits until it) receives data from a remote (IP, PORT), then echoes it back to the client.

CircuitPython UDP Server output:

code.py output:
Connecting to Wifi
Self IP 192.168.6.198
Server ping 192.168.6.198 0.0 ms
Create UDP Server socket ('192.168.6.198', 5000)
Received bytearray(b'Hello, world') 12 bytes from ('192.168.5.32', 20727)
Sent bytearray(b'Hello, world') 12 bytes to ('192.168.5.32', 20727)

UDP Client output (any of the three types):

Create UDP Client Socket
Sent 12 bytes
Traceback (most recent call last):
  File "udp_client_CPython.py", line 29, in <module>
    size, addr = s.recvfrom_into(buf)
socket.timeout: timed out

Checking the tcpdump view of the transaction, we see that the client outgoing port (63312) does not match the CircuitPython-server-printed port (20727). In this case the dump shows the reply going back to the CircuitPython-printed port (20727), BUT this does not work... the reply is never received by the client.

16:03:06.414501 IP: (tos 0x0, ttl 64, id 7958, offset 0, flags [none], proto UDP (17), length 40, bad cksum 0 (->ce78)!)
    192.168.5.32.63312 > 192.168.6.198.5000: UDP, length 12
16:03:06.522949 IP: (tos 0x0, ttl 255, id 56498, offset 0, flags [none], proto UDP (17), length 40)
    192.168.6.198.5000 > 192.168.5.32.20727: UDP, length 12
16:03:06.523016 IP: (tos 0x0, ttl 64, id 64454, offset 0, flags [none], proto ICMP (1), length 56, bad cksum 0 (->f1c7)!)
    192.168.5.32 > 192.168.6.198: ICMP 192.168.5.32 udp port 20727 unreachable, length 36
	(tos 0x0, ttl 255, id 56498, offset 0, flags [none], proto UDP (17), length 40)
    192.168.6.198.5000 > 192.168.5.32.20727: UDP, length 12

I've tried longer timeouts, catching client exceptions and retrying, etc. None of the three types of clients receive the reply back from the native UDP server. All three types of clients do receive replies back from CPython UDP servers (ESP32SPI servers are not supported).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions