An interruption occurs in all TCP socket connections when a socket connection is disrupted, either by disconnecting the Ethernet cable or by powering off the device

Hi,

I have established five TCP socket connections using the Network and RTOS libraries.

uint32_t tcp_cb_func (int32_t socket, netTCP_Event event,const NET_ADDR *addr, const uint8_t *buf, uint32_t len) {
	
   switch (event) 
		 {
		 
		 case netTCP_EventConnect:break;

		 case netTCP_EventEstablished:break;	

		 case netTCP_EventClosed:break;	

		 case netTCP_EventAborted:break;

		 case netTCP_EventACK:break;

		 case netTCP_EventData:break;
		}
		 
		return 1; //1 - incoming connection accepted.
	 
}



void Send_Message_To_TCP(int S){
uint8_t *Mem;	

	
			if (Socket[S].SCK >= 0) 
			{
					if (netTCP_SendReady (Socket[S].SCK))
					{	
						
							Mem=netTCP_GetBuffer (TCP_Size);
							if(Mem==NULL)
							{
								return;
							}
							
							Socket[S].sendbuf = Mem;
							memcpy (Socket[S].sendbuf, TCP_MSG, TCP_Size);
							netTCP_Send(Socket[S].SCK, Socket[S].sendbuf,TCP_Size);
							osDelay(5);							
					}
			}
		
}



__NO_RETURN static void app_main (void *argument)
{


//
//Other Codes
//

//each 30ms
for(i=0;i<5;i++)
{
	Send_Message_To_TCP(i)	
												
}
	
}

The system functions correctly until a TCP connection is disrupted, either by disconnecting the Ethernet cable or by suddenly powering off the device. For instance, when Socket 4's Ethernet wire is disconnected abruptly, the timeout counter starts counting down from 60 seconds. Meanwhile, when a new connection for Socket 3 is accepted and its state changes to 'Established,' it sends only one packet and does not transmit any further data during the timeout period.

As the new connection (Socket 3) begins counting down its timeout, sometimes, the timeout for the previously disconnected Socket 4 is reset to 60 seconds. Consequently, the new connection is disconnected more quickly than the timeout for the previously disconnected socket. Upon investigation, I found that the netTCP_SendReady function only operates after the acceptance of a new connection. After that, it returns false during the established connection, which explains why only one packet is sent.

Socket 4

I also checked the thread priority, and all of them work fine.(I've disabled round robin)

What is my mistake? Any help would be appreciated.

Parents
  • A TCP socket stores data in a memory pool until the remote station acknowledges it. If the Ethernet connection is interrupted, the data is stored until the socket is closed or the data is acknowledged.

    Therefore, it is possible that you have filled the memory pool with data because more sockets are open and sending data. This explains why no new data can be sent. Note that the memory pool is shared by all sockets and services that require dynamic memory.

    TCP sockets have a timer for resending and disconnecting the connection. If the Ethernet cable is disconnected and reconnected before the socket is closed, and both ends have the socket in an established state, TCP socket communication would normally continue and the TCP socket would not even notice the brief disconnection. Retransmission and recovery algorithms correct errors and ensure consistent data transmission.

Reply
  • A TCP socket stores data in a memory pool until the remote station acknowledges it. If the Ethernet connection is interrupted, the data is stored until the socket is closed or the data is acknowledged.

    Therefore, it is possible that you have filled the memory pool with data because more sockets are open and sending data. This explains why no new data can be sent. Note that the memory pool is shared by all sockets and services that require dynamic memory.

    TCP sockets have a timer for resending and disconnecting the connection. If the Ethernet cable is disconnected and reconnected before the socket is closed, and both ends have the socket in an established state, TCP socket communication would normally continue and the TCP socket would not even notice the brief disconnection. Retransmission and recovery algorithms correct errors and ensure consistent data transmission.

Children