Socket in C - Connection test between client and server (Linux)

2

I'm working with sockets in embedded system communication. I create a thread to handle the connection, however as my system uses Wi-Fi connection I need to perform some sort of connection test before sending or receiving, in case this connection goes down I will treat it as soon as it reconnects. Would anyone have any idea how to perform this test?

    
asked by anonymous 22.04.2015 / 23:50

1 answer

1

I found a library called libping found it on Below a usage example (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 have helped

    
13.05.2015 / 22:21