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.