8 years, 9 months ago.

Socket Blocking = False not working on K64F?

Does the set_blocking(false,xxx) work for the K64F?

When running this on the K64F the output stops indefinitely at "Wait for new connection" when it appears that it should continue on after 1.5s. I only have the K64F to test with at the moment so not sure if I'm missing something or if the library is different for the K64F

Example - from https://developer.mbed.org/handbook/Socket

include the mbed library with this snippet

        printf("\nWait for new connection...\n");
        TCPSocketConnection client;
        server.accept(client);
        client.set_blocking(false, 1500); // Timeout after (1.5)s
        
        printf("Connection from: %s\n", client.get_address());

Question relating to:

mbed IP library over Ethernet ethernet, ip, mbed

A clarification on this - the client.set_blocking(false, 1500) is working just fine - but is there a way to have the server.accept not block?

posted by Jeffrey Alexander 03 Aug 2015

1 Answer

8 years, 7 months ago.

i'm discovering similar issues, but my code runs fine till I wan't to read out data.

TCPSocketConnection client;
server.accept(client);
client.set_blocking(false, 200); // Timeout after (200)ms
int i = 0; 

while (true)
{
    printf("goin' to read - %i\r\n", i++);
    int n = client.receive(buffer, sizeof(buffer));
}

That's just a short overview. The loop reads some data, but then it reads no more data. After some more loops the connection is refused. If I use blocking it works much better. But I don't want to use it blocking. Is there some method like client.available() as I had it on the Arduino to see wheter I can read data right now or not?

The error is not the non blocking reading, the error appears when i read <<code>>if(!phy_link_status())<</code>> after every read... But if I read the link status in a ticker function I get no trouble...

posted by Sven Albert 16 Sep 2015