Altera_Forum
Honored Contributor
20 years agoTCP KEEP_ALIVE
Hi,
Is there a restriction on the TCP stack on the use of KEEP_ALIVE option ? I didn't success in using this option : There is no error message, but I can't see any additional exchanges on the TCP exchanges and I get no indication when I disconnect the cable. Maybe I'm wrong in my code, here is an extract :int sockval;
int length;
/* Create the TCP socket */
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
TRACE_CONNECT "Error : cannot create the control socket\n");
return -1;
}
sockval = 1;
length = sizeof(sockval);
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &sockval, length) == -1)
{
TRACE_CONNECT "Warning : KeepAlive option set failed\n");
}
memset(&adsock_server, 0, sizeof(adsock_server));
adsock_server.sin_family = AF_INET;
adsock_server.sin_port = htons(G_JGXEOEinfo.omcpTCPPort);
adsock_server.sin_addr.s_addr = htonl(G_JGXEOEinfo.omcpIPAddress);
if (connect(fd, (struct sockaddr *)&adsock_server, sizeof(adsock_server)) == -1)
{
TRACE_CONNECT "Warning : connection to server (IP=%08X Port=%04X) failed\n", (unsigned int)G_JGXEOEinfo.omcpIPAddress, G_JGXEOEinfo.omcpTCPPort);
}
else
{
//TRACE_CONNECT "Control Application connected to server (IP=%08X Port=%04X)\n", (unsigned int)G_JGXEOEinfo.omcpIPAddress, G_JGXEOEinfo.omcpTCPPort);
return fd;
} Thank you for your contribution.