rendered paste bodyClient( const std::string& host, const std::string& port )
{
struct addrinfo hint;
struct addrinfo* serv;
int sockfd;
memset( &hint, 0, sizeof( hint ) );
hint.ai_family = AF_UNSPEC;
hint.ai_socktype = SOCK_STREAM;
getaddrinfo( host.c_str(), port.c_str(), &hint, &serv );
sd = socket( serv->ai_family, serv->ai_socktype, serv->ai_protocol );
connect( sd, serv->ai_addr, serv->ai_addrlen );
freeaddrinfo( serv );
}
unsigned int send( const unsigned long long i, const char q )
{
const char* str( "some user query" );
char buf[ 512 ];
snprintf( buf, 512, "%s %llu %c", str, i, q );
timeval s;
gettimeofday( &s, 0 );
write( sd, buf, strlen( buf ) );
read( sd, buf, 512 );
timeval e;
gettimeofday( &e, 0 );
return( (e.tv_sec - s.tv_sec ) * 1000000 + e.tv_usec - s.tv_usec );
}