11 years, 1 month ago.

tcp accept blocking

It there a way with the TCP stack to scan for an accept comming in? Now the process stops until the accept is granded by a remote connection. I would like to poll for a connect and continnue with the rest of the processes. For receive there is a way to continue when the return code is zero. But accept does not have such a feature. By the way I am just using the latest Ethernet stack with the TCP socket server.

1 Answer

11 years, 1 month ago.

try this:

//declaration
TCPSocketServer server;
TCPSocketConnection client;
...
//in main section:
server.bind(80); 
server.set_blocking(false); // Timeout after (1.5)s
server.accept(client) ; //here wait 1.5 s and process next code

This option is correct while the mbed is executing a poweron sequence. If the main application is ment to execute processdata a polling if a client wants to connect must be timeless and not take 1.5 seconds. So the code shown above works good, but is not acceptable for a busy application. while blocking is false accept should return immediately with accepted or no client.

posted by Jacques Paul 11 Apr 2013