Dear Mark and all other uTasker users...
I am facing a strange problem... I am observing many TCP connection aborts...
when connecting my device with PC TCP client.
My totology is as below...
PC Client (TCP... Port 502)
|
|
-----------------------------------------------------------------
| | |
Device no 1 Device no 2 Device no n
All devices have the same firmware which have TCP listener on their port 502 (modbus)
What I observed some devices (not all)... hangs after some time... and when I check log
it shows several conenction aborts.. while others who still works dont shows the connection
aborts.
TCP session is as below at PC side:
PC TCP client connects to X device (make TCP Connection) ... take data in close the connection.
and again come to the device after some 3-8 seconds to take new data....
Now I suspect my TCP listner code... which we referred from HTTP listener code from
uTasker's HTTP module.....
May some corrections are needed ... please guide me
Listener code as below..........
/************************************************************************
TCP listener (Max socket created is 3, from the pool).. same declared... in max user socket
macro..
*************************************************************************/
static int fnTestListener(USOCKET Socket, unsigned char ucEvent, unsigned char *ucIp_Data, unsigned short usPortLen)
{
int n,i,Ret=0;
unsigned char TP[30];
TCP_MESSAGE test_message;
switch (ucEvent) {
case TCP_EVENT_CONREQ: if(ucEvent==TCP_EVENT_CONREQ)
{
fnDebugMsg("\r\n---> Req for Conn..");
// debugging info sprintf(TP,"[SockID=%d ] ###",Socket);
fnDebugMsg(TP);
ConReq++;
}
case TCP_EVENT_CONNECTED: if(ucEvent==TCP_EVENT_CONNECTED)
{
fnDebugMsg("\r\n---> Socket Connected..");
// debugging info sprintf(TP,"[SockID=%d] ###",Socket);
fnDebugMsg(TP);
TotCon++;
Con++;
}
case TCP_EVENT_ACK: sprintf(TP,"[ucEvent=%d] ###",ucEvent);
// debugging info fnDebugMsg(TP);
EveAck++;
break; case TCP_EVENT_ARP_RESOLUTION_FAILED: sprintf(TP,"[ucEvent=%d] ###",ucEvent);
fnDebugMsg(TP);
ARP_Fail++;
break; case TCP_EVENT_PARTIAL_ACK: Ret=1;
Par_Ack++;
fnDebugMsg("\r\n->Pack");
sprintf(TP,"[SID=%d]##",Socket);
// debugging info fnDebugMsg(TP);
//return HANDLING_PARTICAL_ACK;
return APP_REQUEST_CLOSE; // This is also suspected !!
break; case TCP_EVENT_REGENERATE: Regn++;
Ret=2;
if(ucEvent==TCP_EVENT_REGENERATE)
{
fnDebugMsg("\r\n--->REGEN");
sprintf(TP,"[SID=%d]##",Socket);
fnDebugMsg(TP);
}
return APP_SENT_DATA; // May this is workaround , and suspected... !! break; case TCP_EVENT_DATA: Rec++;
// sprintf(TP,"[ucEvent=%d] ###",ucEvent);
// fnDebugMsg(TP);
if((MenuFlag==0))
{
TCP_ON=1; /
/Notify Firmware that TCP meg arrive , and in process DecodeMsg(ucIp_Data);
// Decode msg arrived for validity fnDebugMsg("\nucIp_Data =");
for(i=0;i<20;i++)
// Disply Msg {
sprintf(TPgu,"[%u = %x]",i,ucIp_Data);
fnDebugMsg(TPgu);
}
fnDebugMsg("\n");
if(ValidFrame==1)
// Reply Data only if modbus query is valid {
for(i=0;i<TCPd.ResponceLength;i++)
{
if(i<300)
// Copy Modbus reply data in ti ucTCP msg buffer {
test_message.ucTCP_Message=TCPd.RS;
}
}
// Send Data if(fnSendTCP(Socket, (unsigned char *)&test_message.tTCP_Header, TCPd.ResponceLength, TCP_FLAG_PUSH) > 0)
{
return APP_SENT_DATA; }
}
else
{
fnDebugMsg("\n@ Not valid Frame..@");
//return APP_SENT_DATA;
// May this is not correct }
TCP_ON=0;
}
else
{
//return APP_SENT_DATA;
// May this is not correct }
break; case TCP_EVENT_ABORT: if(ucEvent==TCP_EVENT_ABORT)
{
TotAbort++;
Con--;
fnDebugMsg("\r\n---> Aborted..");
// debugging info sprintf(TP,"[SockID=%d] ###",Socket);
fnDebugMsg(TP);
}
case TCP_EVENT_CLOSED: if(ucEvent==TCP_EVENT_CLOSED)
{
TotClose++;
Con--;
fnDebugMsg("\r\n---> CLOSED..");
// debugging info sprintf(TP,"[SockID=%d] ###",Socket);
fnDebugMsg(TP);
}
fnTCP_Listen(Socket, usTestPort, 0);
// go back to listening state on next port number // I dont know weather this is correct ... and // not leading to many partial opened connections break; }
return APP_ACCEPT; // This is also suspected !!! why I return this as default}