TCP Client [wiring] ERROR: recv error = 128

Using the TCP Client to communicate with another device and it will work for a while and then I get a [wiring] ERROR: recv error = 128 after sending a block of data(1300 - 1400 bytes in size).
What does this error actually mean and how can I prevent it?

I assume it is coming from int TCPClient::available() in spark_wiring_tcpclient_posix.cpp and this code then closes the socket.

I have tried SINGLE_THREADED_BLOCK() and nointerrupts() around the send and receive routines.

Device is connected to Particle at the same time.

Currently trying it on DeviceOS 5.9.0 on an Argon

It's not clear what that is. It's an error code from sock_recv() but 128 is not a normal errno. Farther in it comes from lwip_recv() but that doesn't seem like a valid errno code for LWIP either.

I'd guess either a buffer is full or the other side closed the connection.

In any case, don't attempt to make networking calls with interrupts or threading disabled. There's a good chance that the system will deadlock if a buffer is full.

1 Like

The error code is coming from newlib, the standard C/C++ library.

#define ENOTCONN 128		/* Socket is not connected */

The socket disconnected so you can no longer read from it.

1 Like

The ERROR: recv error = 128 error was actually when using DeviceOS 5.6.0 I had reverted to it as we know it was stable.

Tried DeviceOS 5.9.0 and now getting [wiring] ERROR: recv error = 113

The POSIX error codes are now in the docs.

113 is connection aborted, which is what you get if the connection is abruptly closed. I think it can also happen if a router between the two sides loses the route to the other side.

1 Like

Finally tracked the problem down to a pointer to data storage that no longer existed giving nonsense data that the far end didn't like and it was closing the connection.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.