Hi,
OK it works fine. The main difference with "standard" code that I could seen, is the need to set IPPROTO_TCP in the socket function call (instead of 0).
For convenience, I give the final code that works fine :
<div class='quotetop'>QUOTE </div>
--- Quote Start ---
if ((fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
{
TRACE_CONNECT "Error : cannot create the control socket\n");
return -1;
}
/* Set options of that socket */
sockval = TCP_KEEPIDLE_VALUE;
if (setsockopt (fd, SOL_TCP, TCP_KEEPIDLE, (void *)&sockval, sizeof(sockval)) == -1)
{
TRACE_CONNECT "Warning : TCP_KEEPIDLE option set failed\n");
}
sockval = TCP_KEEPCNT_VALUE;
if (setsockopt (fd, SOL_TCP, TCP_KEEPCNT, (void *)&sockval, sizeof(sockval)) == -1)
{
TRACE_CONNECT "Warning : TCP_KEEPCNT option set failed\n");
}
sockval = TCP_KEEPINTVL_VALUE;
if (setsockopt(fd, SOL_TCP, TCP_KEEPINTVL, &sockval, sizeof(sockval)) == -1)
{
TRACE_CONNECT "Warning : TCP_KEEPINTVL option set failed\n");
}
sockval = SO_KEEPALIVE_VALUE;
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &sockval, sizeof(sockval)) == -1)
{
TRACE_CONNECT "Warning : KeepAlive option set failed\n");
}
/* Permanent try of connection */
while (1)
{
memset(&adsock_server, 0, sizeof(adsock_server));
adsock_server.sin_family = AF_INET;
adsock_server.sin_port = htons(TCPPort);
adsock_server.sin_addr.s_addr = htonl(IPAddress);
if (connect(fd, (struct sockaddr *)&adsock_server, sizeof(adsock_server)) == -1)
{
TRACE_CONNECT "Warning : connection to server failed\n");
}[/b]
--- Quote End ---