Keeping TCP Socket Alive

I am calling TCPClientCreate Function to create a TCP Socket every 30 Secs.
I am using Q2687, FW 7.4 and O.S. 6.30.

I want to Keep The TCP Socket Alive for the Whole GPRS Session using TCPClientCreateOpts Function.
Is it Possible :question:

Kindly give an advise !!! :wink:

The only way to be absolutely certainly that the socket is fully alive with working end-to-end connection is to send something to the remote host, and receive its reply.

Search this forum for “heartbeat” and “keep-alive”…

@ awneil
Thanks for the reply.

Once a TCPClientCreate Function is called, a single Tx and Rx is invoked by the event handler.
No more Read or Write Events Occur without calling the TCPClientCreate Function again.
And calling TCPClientCreate Function agian creates a newTCPclient.

How a multiple Read / Write can be performed with a single TCPClientCreate Function Call.
Kindly provide a sample code if possible.

How to Invoke multiple Write Events in a single TCPClientCreate Function Call. :question:
I will be greatful for the help extended.

Have you studied the WIP User Guide - particularly the event descriptions and the state diagram for the TCP Client socket :question:

Have you looked at the examples included in the SDK :question:

@awnil Thanks

Yeh I have seen documents and samples in detail.
My understanding is that TCP Socket Event Handler is invoked once socket is created and subsequently when wip_Read or Wip_write value is greater than RCV_Buffer or SND_BUffer size.
Thats a sort of self invoking.

How can I keep the socket alive for indefinite period and Invoke a Write or Read Event from Code at any time required. Ideally I want to put the socket in an Idell state and use it whenever required without initiating a new_TCPclientCreate request.

Regards

You don’t have to call TCPclientCreate every time you want to read or write from the socket, only once to create the client connection to the server.

TCP_Socket = wip_TCPClientCreate(ServerDetails.IP_address, ServerDetails.IP_port, pfk_tcpEventHandler, NULL);	// Create the COMMS_TCP client connection to the server.

The client connection will remain open indefinitely, unless terminated by the host or your network connection fails (or some error occurs). As awneil says, the only way to be sure that it is connected is to send or receive messages from your TCP server.

Once you have created the TCP client connection, used the wip_channel_t structure returned by TCPclientCreate to send packets, ie:

u16 nwrite = wip_write(TCP_Socket, Write_data, length);			// Write to the TCP client connection

This can be done any time after the client is created (assuming it hasn’t been closed by the server of an error has occured)

If the server sends data to the client, the TCP event handler that was provided in the TCPclientCreate function is called with the WIP_CEV_READ event. You must then perform a wip_read to get the data:

nread = wip_read(ev->channel, rcv_buffer, sizeof(rcv_buffer));

Note that you should only perform a wip_read from the channel when there is actually data waiting in the TCP buffer, ie when the TCP event handler has been called.

You can set the TCP send and receive buffer sizes to change when the TCP event handler is called (you only want to call the handler after your entire data packet has been received). The socket will remain idle but connected when there is no data to send of receive.

@ tomridl

I was away from this forum for some days, Although I had learnt TCP Socket Alive method through a hard way, I still am grateful for your reply.

Many a thanks for kind and very exact answer.

You are dead right!

I wish i had visited the group regularly. :frowning:

Thanks and Regards… :smiley: