I'm trying to use the BufferedTcpObject with an SBL2e, but it appears that the timeout parameter on the Connect call does not work, instead the Connect call blocks forever - and even if the server shows up later, the connect never completes.
hello awdorrin and paul even I'm trying to use the BufferedTcpObject with an SBL2e, but it appears that the timeout parameter on the Connect call does not work, instead the Connect call blocks forever - and even if the server shows up later, the connect never completes.
kindly find the below code is it correct what changes i have to do:
static BYTE buffer[256];
BufferedTcpObject tcp(buffer, 256, NULL);
// enter processing loop
while (1) {
if (!tcp.Connected()) {
iprintf("TCP attempting connection to %I : %d\r\n ", DestIP, DestPort);
OSTimeDly(5);
if (tcp.Connect(DestIP, DestPort, 40)) {
iprintf("Connected to server...\r\n");
} else {
iprintf("Connection failed... waiting 5 seconds before retrying...\r\n");
// wait before trying to reconnect to remote server
while ( (rcount < 5 * TICKS_PER_SECOND)) {
rcount++;
OSTimeDly(1);
}
rcount = 0;
}
}
else {
// do something after connected
}
}
There are a couple of points of concern for me with your code.
1. Are you saying that you *never* see the iprintf text:
iprintf("Connection failed... waiting 5 seconds before retrying...\r\n");
2. You should use TICKS_PER_SECOND to make your code easier to read, especially since the ticks per second count can be changed so that 20 ticks is not one second. In your connect call you use 40. If that is indeed 2 seconds in your configuration you need to make that longer. For 2 seconds use TICKS_PER_SECOND * 2. For half a second use TICKS_PER_SECOND / 2, etc.
3. You state that "blocks forever - and even if the server shows up later, the connect never completes." How is it that your server comes and goes? Maybe there is a larger problem here in that a server that comes and goes is creating a situation in which sockets are not getting closed properly, a connection already exists, half open socket, etc. I would try some much longer timeouts to determine how the system is really functioning, like timeouts of 10 seconds and 30 seconds between attempts. Note if connections are ever made and if the blocking you see only occurs after a certain sequence, etc.