Hi there,
This Echo Server that accept 3 connections seems to work well with one clients (run for a weekend long without disconnecting), but when there is 3 clients connected to it, it seems to stop after few hours (disconnect). Any idea what could be wrong in my code?
The clients sends a frame (len=1400) right after receiving the echo from the server.
/**************************************************************************
* M A C R O S *
***************************************************************************/
#define TCP_ECHO_PORT_NUMBER 950
#define TEST_BUFFER_LENGTH 1400
#define MAX_TCP_SOCKETS 3 // Accept 3 sockets on port 950
/**************************************************************************
* L O C A L P R O T O T Y P E S *
***************************************************************************/
static int fnTestListener(USOCKET Socket, unsigned char ucEvent,
unsigned char *ucIp_Data, unsigned short usPortLen);
/**************************************************************************
* T Y P E D E F I N I T I O N S *
***************************************************************************/
typedef struct stTCP_MESSAGE
{
TCP_HEADER tTCP_Header; // reserve header space
unsigned char ucTCP_Message[TEST_BUFFER_LENGTH];
} TCP_MESSAGE;
/**************************************************************************
* FUNCT: fnEchoServerInit
*
* starts the echo server
***************************************************************************
* C O D E
***************************************************************************/
extern void fnEchoServerInit( void )
{
static USOCKET tcp_socket1 = -1;
static USOCKET tcp_socket2 = -1; // declare a static socket variable
static USOCKET tcp_socket3 = -1;
static unsigned short usTestPort = TCP_ECHO_PORT_NUMBER; // declare a port number
// create a TCP socket with a tim out of 60 sec
tcp_socket1 = fnGetTCP_Socket(TOS_MINIMISE_DELAY, (unsigned short)60, fnTestListener);
tcp_socket2 = fnGetTCP_Socket(TOS_MINIMISE_DELAY, (unsigned short)60, fnTestListener);
tcp_socket3 = fnGetTCP_Socket(TOS_MINIMISE_DELAY, (unsigned short)60, fnTestListener);
// bind socket to listening port number
fnTCP_Listen(tcp_socket1, usTestPort, 0);
fnTCP_Listen(tcp_socket2, usTestPort, 0);
fnTCP_Listen(tcp_socket3, usTestPort, 0);
}
static int fnTestListener(USOCKET Socket, unsigned char ucEvent, unsigned char *ucIp_Data, unsigned short usPortLen)
{
TCP_MESSAGE test_message;
char dbugstr[50] = {'E', 'm', 'p', 't', 'y', '/0'};
switch (ucEvent) {
case TCP_EVENT_CONREQ:
fnDebugMsg("TCP Connection request received\r\n");
break;
case TCP_EVENT_CONNECTED:
sprintf(dbugstr, "TCP Connection established on socket no. %d\r\n", Socket);
fnDebugMsg(dbugstr);
break;
case TCP_EVENT_CLOSE:
fnDebugMsg("TCP Connection stop request\r\n");
break;
case TCP_EVENT_ACK:
case TCP_EVENT_ARP_RESOLUTION_FAILED:
case TCP_EVENT_PARTIAL_ACK:
break;
case TCP_EVENT_REGENERATE:
case TCP_EVENT_DATA:
sprintf(dbugstr, "usPortLen = %d\r\n", usPortLen);
fnDebugMsg(dbugstr);
// send copy
if (uMemcpy((CHAR*)test_message.ucTCP_Message, (CHAR*)ucIp_Data, usPortLen)) {
if (fnSendTCP(Socket, (unsigned char *)&test_message.tTCP_Header, usPortLen, TCP_FLAG_PUSH) > 0) {
return APP_SENT_DATA;
}
}
else
fnDebugMsg("uMemcpy failed\n\r");
break;
case TCP_EVENT_ABORT:
case TCP_EVENT_CLOSED:
fnTCP_Listen(Socket, TCP_ECHO_PORT_NUMBER, 0); // go back to listening state on next port number
fnDebugMsg("TCP Connection fully closed\r\n");
break;
}
return APP_ACCEPT;
}
What do you think of that strategy to test the TCP/IP stack?
Having just written a bunch of code that effectively stresses uTasker TCP
Can you tell here what are your strategies for testing a tcp/ip stack?
Thanks
FB