TCP WIP_CEV_EEROR event


#1

Hy guys,

I have an application that looks like this :


I wrote the application that takes the Modbus message from the SCADA, sends it to the serial interface, waits for response and then forwards the response back to the SCADA application.
All works fine for about 2minutes and a half. After that i receive a WIP_CEV_ERROR event in the tcp handler.
When i read the ev->content.error.errnum it gives me -1000. That means WIP_CERR_ABORTED.
But the data continues to be sent ok, even if i close the channel in case of an error.

I cannot understand why this happens. Maybe someone encountered this type of problem or has a better understanding of WIP library.

This is my code :

Creating the TCP server

void TCPCreate()
{
	TRACE((1, "TCP CREATE FUNCTION"));
	wip_channel_t c;
	c = wip_TCPServerCreate (8080, TCPHandler, NULL);
}


TCP Handler

void TCPHandler(wip_event_t *ev, void *ctx)
{

	u8  lbuffer[1000];
	u16 i;

	TRACE((1, "TCP HANDLER"));
	c = ev->channel;

	switch (ev->kind)
			{
				case WIP_CEV_OPEN:
					 break;

				case WIP_CEV_READ: //Data on the socket
					 nread = wip_read(c, lbuffer, sizeof(lbuffer));
					 TRACE((1,"nread = %d",nread));
					 buffer = (u8 *) malloc(sizeof(u8[nread]));
					 for (i=0; i<=nread;i++)
						{
							buffer[i] = lbuffer[i];
						}
					 DUMP(1,buffer,sizeof(u8[nread]));
					 sendData();
					 break;
				case WIP_CEV_ERROR:
					TRACE((1,"Channel Error - %d",ev->content.error.errnum));
					adl_atSendResponse(ADL_AT_RSP, "Channel Error\n\r");
					TRACE((1,"Close channel : %d",wip_close(c)));
					break;
				case WIP_CEV_PEER_CLOSE:
					 TRACE((1,"Peer close connection"));
					 break;
				case WIP_CEV_WRITE:
					 TRACE((1,"WIP_CEV_WRITE"));
					 break;
			    default:
				break;
			}
}

Function that forwards data received from TCP to the serial interface

void sendData()
{
	s8 result;

	result = adl_fcmSendData(fcm_Handle,buffer,nread);

	if (result == 0 )
		{
		TRACE((1,"Data sent - [OK]"));
		free(buffer);
		}
		else
			{
			TRACE((1,"Data sent - [ERROR]"));
			free(buffer);
			}
}

FCM Data Handler

bool DataHdlr(u16 Datalen, u8 * Data)
{
    if (Datalen!=0)
		{
		wip_write(c, Data, Datalen);
		adl_fcmReleaseCredits(fcm_Handle, 0xFF);
		}

	return true;
}

Hope i was clear enough describing my problem…
Thanks in advance!


#2

No one can tell me what i’m doing wrong or why the event appears ?:frowning:


#3

Hi
The event “WIP_CERR_ABORTED”(error code: -1000) event is received when read/write is tried on the aborted TCP client i.e. the TCPconnection is reset by the peer or the user but the read/write operation is tried on the aborted TCP client.

The described problem might occur because of the problem in the following layers

  1. GPRS layer: To check whether the GPRS services are working fine; please subscribe to the adl_gprsSubscribe () API which will enable the GPRS related events.

  2. Bearer level: The events received in the call back handler can be used to check the cause of the failure at the bearer level.

  3. Socket layers: Some events, especially. the error events, might put a channel in a unusable state. Hence to check the present state wip_getState () API can be used.


#4

I see…the odd thing is that i receive this error after some of exchange of data…

The Scada TCP client sends a message and after receiving a response or after the timeout period it closes automatically the socket, cause i receive after every exchange of data WIP_CEV_PEER_CLOSE event. At the next data request it opens another socket…and so on…maybe this is the problem…

This is the traces from a transaction… i receive the modbus message from tcp channel(4C 03 00 05 00 09 9A 10 ) after receiving i send the message over the serial link (Data sent - [OK]) and after receiving the response the TCP client closes the connection.

11/06/29,09:31:39:481 - 001;ADL;1;4C 03 00 05 00 09 9A 10 
11/06/29,09:31:39:483 - 001;ADL;1;Data sent - [OK]
11/06/29,09:31:45:601 - 001;ADL;1;Peer close connection

After a while the error appears

11/06/29,09:34:32:716 - 001;ADL;1;nread = 8
11/06/29,09:34:32:721 - 001;ADL;1;4B 01 00 00 00 23 73 B9 
11/06/29,09:34:32:725 - 001;ADL;1;Data sent - [OK]
11/06/29,09:34:38:748 - 001;ADL;1;Peer close connection
11/06/29,09:34:43:410 - 001;ADL;1;Channel Error - -1000

But nothing happens to my application…on the SCADA part i can see reading errors…and it’s all ok…in the cabled environment i still had some minor errors…

I’m worried if the app can crash because of this error…


#5

Note that WIP_CERR_ABORTED is an error code - not an Event.

If the remote peer is closing the channel, you should be getting a WIP_CEV_PEER_CLOSE Event.

This does show that the Peer is closing the connection!

So a WIP_CERR_ABORTED is to be expected if you attempt to do anything further with that connection!


#6

You are right…i get a WIP_CEV_PEER_CLOSE after receiving the message but the idea is that i receive the message, read the request into a buffer and send a response that i receive on the serial link…after receiving the response the client closes the socket but at this point my app shouldn’t do anything with that channel anymore, and still i get WIP_CERR_ABORTED.

And another question will be why these doesn’t happen from the beginning…only after an amount of time i get the error…


#7

Dear capitanui,
Could you fix your problem? I have the same problem.

Thank you

anna.


#8

No anna…i didn’t fix the problem…it’s still there…but i get no error…my application functions as it needs to but i receive this event…i don’t know why because i don’t try to do anything else after the peer closes the connection…i just close and clear the channel…