TCP Timeout ?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

TCP Timeout ?

2,924 Views
IamX
Contributor I
Hi all
I use NE64_Vend_openTCP.
I initial follow code below.
Code:
void tcp_x_init(void){    WriteToSCI1("Initializing TCP server application. \r\n");    tcp_soch = tcp_getsocket(TCP_TYPE_CLIENT, TCP_TOS_NORMAL, TCP_DEF_TOUT, tcp_control_panel_eventlistener);    if( tcp_soch < 0 )    {            WriteToSCI1("TCP server unable to get socket. Resetting!!!\r\n");            RESET_SYSTEM();    }else{      WriteToSCI1("TCP Get Socket Client Type!!!\r\n");    }    (void)tcp_connect(tcp_soch,0xC0A800C7,2002,TCP_PORT+2);}

 and listener funtion below
Code:
INT32 tcp_control_panel_eventlistener(INT8 cbhandle, UINT8 event, UINT32 par1, UINT32 par2){INT32 i;par2++; // to avoid the compiler warning if( cbhandle != tcp_soch)  /* Not our handle */  return(-1);  switch( event ) {   case TCP_EVENT_CONREQ:   WriteToSCI1("TCP: Connection request arrived!\r\n");   return(1);   break;   case TCP_EVENT_ABORT:   WriteToSCI1("Connection aborting!\r\n");    break;  case TCP_EVENT_CONNECTED:   WriteToSCI1("TCP: TCP connection established!\r\n");   break;  case TCP_EVENT_CLOSE:   WriteToSCI1("TCP Connection closing...!\r\n");   break;  case TCP_EVENT_ACK:   WriteToSCI1("TCP: Data acknowledged!\r\n");    break;     case TCP_EVENT_DATA:   WriteToSCI1("TCP: Data arrived!\r\n");     if(par1 <= 0)         break;       for(i=0;i<par1;i++)          {            TCP_In_Msg[i]=RECEIVE_NETWORK_B();          }           WriteToSCI1("Get data from server : ");           WriteToSCI1(TCP_In_Msg);           WriteToSCI1("\r\n");   send_ack_data();      tcp_send_buffer();   break;     case TCP_EVENT_REGENERATE:      tcp_send_buffer();   break;    default:   return(-1); }}
 
I connected and send/receive data.
After I not send/receive about few minute.
I can't send/receive data again.
How to solv this problem ?
or
What wrong I do.?
 
Thank you for advantage
Mr.X
 
Labels (1)
0 Kudos
4 Replies

676 Views
IamX
Contributor I
Thank you for all reply.
How to send keep-alive packets ?
I just learning TCP Stack.
 
Thank You
Mr.X
0 Kudos

676 Views
williamskj
Contributor I
As pittbull said, you just have to send messages with no data to the NE64. You have to send them periodically with an interval less than that of the timeout. You just send a normal message but with no data (i.e. just the header). Alternatively, you can send data if you want - maybe a code number (9999 ?) that tells your NE64 code that this is a stay-alive message and program the NE64 code to just ignore messages with this code - i.e. do not perform any further processing on it. The point is that it is just a dummy message which exercises the tcp code and therefore keeps the connection open.
0 Kudos

676 Views
pittbull
Contributor III

Hello,

OpenTCP differs from other TCP stacks that it drops connections if there's no activity.

Normally, this task should be assigned to the application, not the transport layer.

If you want to get rid of that unusual behaviour, you can modify OpenTCP or send keep-alive packets (packets with no data).

   

0 Kudos

676 Views
williamskj
Contributor I

Hi,

There is a tcp timeout defined in tcp_ip.h ......

/** \def TCP_DEF_TOUT
 * \ingroup opentcp_config
 * \brief Default idle timeout
 *
 * This period defines idle timeout in seconds - this feature allows
 * TCP/IP stack to close the TCP connection if no data has been exchanged
 * over it during this period of time. This relates ONLY to data. Empty
 * keep-alive TCP packets are not included.
 */
#define TCP_DEF_TOUT  120 //two min. 

 

Karl

0 Kudos