TCP socket waits for a char

14 Oct 2012

Hi,

The program contains;

EthernetInterface eth; eth.init(); eth.connect(); pc.printf("IP Address is %s\n\r", eth.getIPAddress());

TCPSocketServer server; server.bind(ECHO_SERVER_PORT); server.listen(); pc.puts("\r\nWait for new connection...\n\r"); TCPSocketConnection socket; server.accept(socket); socket.set_blocking(true); int n = socket.receive(buffer, 1);

All works OK but the socket.receive waits until a char to arrive, this locks up my program.

Is there a way to know upfront that the buffer contains a character?? then i can prevent the locking up.

Thanks, Gerrit

15 Oct 2012

Hi Garrit -

Have you read about blocking and non-blocking on the Sockets page? There is also some explanation about this function in the comments on that page, specifically from Emilio on August 8, 2012.

https://mbed.org/handbook/Socket

You have blocking set to TRUE in your code above, so it will wait forever. You could set it to FALSE and give it a timeout value.

I hope that helps,

Mike

16 Oct 2012

Hi Mike,

Thanks for your info,I will give it a shot and see what happens. Thanks again,

Gerrit

17 Oct 2012

Mike,

It works like a charm. Thank you very very much

Gerrit