05-24-2010 03:04 PM
Is there a way for a TCP Client to determine or detect that a Server has dropped -- ie, cable disconnected, server application quit, etc?
I have a client and server. The client connects, then sends messages to the server, the server replies. If the server drops, the client continues to send messages, using ClientTCPWrite, and does not get an error code in return. Return value continues to be '0', as though there is success.
If I send a GetTCPPeerAddr(...) after the server is disconnected, the function returns '0' (success), and the IP address returned is the IP of the disconnected computer.
It does not look like there is anything in the TCP support library that can test the aliveness of a TCP Server.
05-24-2010 03:22 PM
When you use ConnectToTCPServer function you need to pass callback function. and look for TCP_DISCONNECT event.
Here is help.
The name of the function to be called to process messages to your program as a TCP client. A NULL pointer is not allowed.
The callback function must be of the following form:
int (*tcpFuncPtr) (unsigned handle, int xType, int errCode,
void *callbackData);
The 'handle' parameter contains a value that is unique to each client-server connection.
The 'xType' parameter contains the TCP transaction type. The following list specifies all of the transaction types that can be received by clients:
TCP_DISCONNECT
TCP_DATAREADY
The 'errCode' parameter is used only when the transaction type is TCP_DISCONNECT.
The following describes each transaction type.
TCP_DISCONNECT - Received when a server is requesting the termination of a connection, or when a connection is being terminated due to an error. If the connection is being terminated due to an error, the 'errCode' parameter contains a negative error code. Otherwise the 'errCode' parameter contains zero. (See the help for the Status control for the list of error code values.)
TCP_DATAREADY - Received when the server has sent data via TCP to the client. Your program, acting as the client, should call
ClientTCPRead to obtain the data.
Remarks:
--------
The return value of the callback function is ignored.
The callback function should be short and return as soon as possible.
05-24-2010 04:02 PM
test_man,
Apparently you did not read my post. I have a client and server running properly on two computers, passing traffic. I need to find a way for the client to detect that the server has dropped. The client side TCP driver never issues a TCP_DISCONNECT event, and the TCPClientWrite function never returns an error, even if the Server network cable has been disconnecte.
Next idea?
05-25-2010 12:05 AM
Hi hendra,
Actually, test_man is correct.
When the server drops/disconnects your client-side callback (which you pass to the connect function as a parameter) will automatically receive an event of type TCP_DISCONNECT.
I have used the same in a project of mine that is working in that sense.
If you put the following statement in the client callback, you will see what we mean:
switch (xType)
{
case TCP_DATAREADY:
// code for handling data transfer from the server
break;
case TCP_DISCONNECT:
// code for handling server drop
break:
}
05-25-2010 08:07 AM
Eren and Test_man,
Pardon my prior terseness. Perhaps I am trying to do something that the TCP driver is not capable of supporting..
I have the code to detect the TCP_DISCONNECT event in my callback. It works fine if the Server disconnects the client. It works fine if the Server application is quit, and the OS disconnects the client automatically.
It does NOT work if the Server computer network cable is disconnected, ie, some anomolous event. If a cable is disconnected, the Client continues to believe it is connected, and there does not seem to be any way to detect that there is no Server out there. Writing to the port appears successful all the time, even though the driver is writing to a disconnected cable. It just seems to me there there ought to be some handshaking going on, so that a Write returns an error.
The only thing I can think of here is to put a watchdog timer in the code, to wait some seconds after not hearing from the server, and then disconnect and try to reconnect.
05-25-2010 08:51 AM
That can be a good approach.
You can send some "i-am-alive" packages from the server periodically.
Then the client can reset a timer at each alive package and rise and alert if the timer counts down to 0.
05-02-2012 04:58 AM
Hi,
I am new in LabVIEW and I am using TCP communication protocol to send mix Data(Numeric, boolean) from 5 client(5 PC) to the RT Target. We are sending different data from different Host PC to the RT target. I am using TCP listener in RT target and TCP open coneection in PCs. Here I am facing problem is that every time I have to run RT vi first and then host PCs VI. If I am running PC vi first I am getting error 63 occured at TCP open connection. Is there any solution for this? Is there any possibility to communicate if I run the any one of the VI first?
Also I am not able to make a connection , Disconnection and connect to all connection switch to connect the network(communication) between different PC to RT Target. If you have any idea about this, please let me know.
Thanks!
05-02-2012 05:47 AM - edited 05-02-2012 05:49 AM
Hello Srikant Kumar,
although this discussion addresses some TCP topics, it is strictly related to CVI language. Since you are using Labview, I suggest you post your questions to the appropriate forum.