Read your config file and then create a thread for each server entry. Every thread should do this:
for (;;) {
bool connect_success = connect_to_server();
if (connect_success)
{
for (;;)
{
if (send_request())
{
if (receive_response())
{
}
else
{
break;
}
}
else
{
break
}
}
}
Sleep(1000);
}
There is no "checking connection" functionality in the socket api. You find out if the connection is still alive only when you try to send or receive data and the send/recv function returns with error. This is why the
send_request()
and
receive_response()
functions in my example return a
bool
to indicate error.