pico-examples icon indicating copy to clipboard operation
pico-examples copied to clipboard

Test always fails with tcp server example

Open berwil-1 opened this issue 2 years ago • 1 comments

Running the TCP server example on my Pico W always fails silently on the server when testing with the provided Python client test script.


Tracked the first issue to this if statement that catches if an empty buffer has been received. It seems to always occur at the end of the test run: https://github.com/raspberrypi/pico-examples/blob/eca13acf57916a0bd5961028314006983894fc84/pico_w/wifi/tcp_server/picow_tcp_server.c#L117


Tracked the second issue to tcp_client_err where the err is not err_abort but err_reset every time the Python client is done with the test run. The Python script should close gracefully with sock.close() but this does not seem to be the case for me. https://github.com/raspberrypi/pico-examples/blob/eca13acf57916a0bd5961028314006983894fc84/pico_w/wifi/tcp_server/picow_tcp_server.c#L163


I would expect the test to successfully run at all times and explain why it fails if it fails in all cases.

berwil-1 avatar Jun 15 '23 08:06 berwil-1

Ran into a version of this today when working on the picow_tcp_client.c example. Even though my server was sending data and my client was receiving it correctly, the client was always reporting failure due to this test in tcp_client_recv.

The lwip documentation for tcp_recv states:

The callback function will be passed a NULL pbuf to indicate that the remote host has closed the connection.

Which seems to me to not be an error condition, but merely the usual way that you know that a server is done with you.

For the record, I had my client code (copied from picow_tcp_client.c) do the following in this case:

return tcp_result(arg, ERR_OK);

Happy to submit a PR for this, if it would help.

eelstretching avatar Jul 08 '23 20:07 eelstretching