Keep Alive in mac os Socket
Hi
I would like to implement a socket that will send the keep alive message to the server in a regular interval. So that we can get the server status (active / inactive). I tried using keep alive but I am not able to send the keep alive message to server.
I have implemented below code
int nsockOptVal = nOnOff;
int nAliveIntervalSec =60;
retCode = setsockopt(m_nSockFD, SOL_SOCKET, SO_KEEPALIVE, (void *) &nsockOptVal, sizeof(nsockOptVal));
if (retCode < 0)
{
Show error
return false;
}
if ((retCode=setsockopt(m_nSockFD, IPPROTO_TCP, TCP_KEEPALIVE, (void *) &nAliveIntervalSec, sizeof(nAliveIntervalSec))) < 0)
{
Show error
return false;
}
Can any body tell me what is wrong?
|