LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

TCP Reading

Hello All,
 
I am writing a TCP/IP client that connects to a server using 'ConnectToTCPServer'. The client sends various commands to the server which are then returned.  For what I am doing, using the asynchronous callback created with the 'ConnectToTCPServer' call is rather unwieldy.  However I noticed that simply calling 'ClientTCPRead' directly after 'ClientTCPWrite' seems to work while allowing me to bypass the asynchronous callback created in 'ConnectToTCPServer' (at least in my version of CVI 7.0).  My question is, are there any problems that might occur from using 'ClientTCPRead' directly instead of using it within the callback created by 'ConnectToTCPServer'? 
 
The one problem that I can see is that if there are multiple client connections to the server then I won't know which client the data I am reading is meant for.  But for the purposes of my application only one client can be connected to the server at a time, so this would not be an issue.  
0 Kudos
Message 1 of 3
(3,377 Views)
Hello DaveC..

You are forced to specify a (non-NULL) callback function when you call ConnectToTCPServer(), but you can do whatever you like in the callback, including ignoring the TCP_DATAREADY event. However, consider:
  • You probably need to handle the TCP_DISCONNECT event, so that you can re-connect, clean up, whatever.
  • Can you guarantee that the server will not transmit except immediately after you call ClientTCPWrite()? If not, you probably should handle TCP_DATAREADY when you are not expecting any data.
  • What will happen when there is a lot of network traffic?
  • Make sure you read all available data when you call ClientTCPRead(); otherwise, your client and server may get out of sync.
Your client will only see the data sent to it (not other clients). There will be a unique "conversation handle" for each client. You get this handle when you call ConnectToTCPServer().

Good luck.

Regards,
Colin.

Message 2 of 3
(3,367 Views)

Two clarifications:

1) The TCP callback is synchronous and not asynchronous.

2) You can pass NULL (0) for the Callback parameter of ConnectToTCPServer and ConnectToTCPServerEx in CVI 7.1.

Best regards,

Mohan

0 Kudos
Message 3 of 3
(3,341 Views)