You cannot send data to a remote host before it initiates a connection. It just doesn't make any sense. My question is: do you want your device to connect to the remote host, or do you want the remote host to initiate a connection to your device?
You are currently using netconn_accept on your device - this means that you expect the remote host to initiate a connection to your device before your device can signal to the remote host. This is the fully expected behavior for the code you wrote, but you seem to be worried about this. Isn't that your intention? If not, why did you code it? Another alternative is for your device to initiate a connection to the remote host. Here is an example of using netconns here . Of course, this is also due to changes on another device in your system.
So, the moral of this story is that you cannot send any data when there is no connection, and you are waiting for the connection before sending data. You do not want to wait for the connection, so you need to change your software to initiate the connection, and not wait until the other side initiates the connection.
Another problem that you may encounter is that you want to send and receive data at the same time on the same connection. Most of the examples I've seen for lwip include blocking calls waiting for data, and then responding to that data by passing something back. Sometimes you want to convey something without first receiving something. I can help too.
This is what worked for me when I created a netconn listening connection.
First you must enable timeouts by setting:
#define LWIP_SO_RCVTIMEO 1
Then you need to configure your netconn in the same way:
pxTCPListener = netconn_new (NETCONN_TCP);
netconn_bind (pxTCPListener, NULL, 23);
netconn_listen (pxTCPListener);
pxNewConnection = netconn_accept (pxTCPListener); // This blocks until the connection is accepted
// This is an important line!
pxNewConnection-> recv_timeout = 10; // note This is millseconds - lwip works in ms
// This is a loop until the connection is closed
while (! ERR_IS_FATAL (pxNewConnection-> err)) {// Fatal errors include closed connections, reset, aborted, etc.
// This netconn_recv call now waits 10 ms for any new data, and then returns
if ((pxRxBuffer = netconn_recv (pxNewConnection))! = NULL) {
// Processing the received data
}
// This is where any transfers you want are made
} // End of while loop above
This code will allow you to make transfers and receive at the same time, without worrying about blocking.