C socket - Client-server connection test (Linux)

Asked

Viewed 609 times

2

I’m working with sockets in embedded system communication. I create a thread to handle the connection, but as my system uses Wi-Fi connection I need to perform some way a connection test before sending or receiving, in case this connection falls I treat it right away to reconnect. Would anyone have any idea how to perform this test?

1 answer

2


I found a library called libping I found her in the vivaolinux

Below an example of usage (also found in the link above)


/* main.c */
#include <stdio.h>
#include <ping.h>

int
main( int argc, char *argv[1] )
{
    if( pinghost( argv[1] ) > 0 )
        printf( "%s is alive\n", argv[1] );
    else
        printf( "%s is unreachable\n", argv[1] );

    exit( 0 );

}

I hope I’ve helped

Browser other questions tagged

You are not signed in. Login or sign up in order to post.