LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

TCP Client question

I am trying to write a TCP Client program. Connecting to the server is no problem. What I need to do next is write to the server and then wait for an answer before going on to my next line of code. The problem is I use ClientTCPWrite to send the message to the server but my program is going on to the next line of code before the server has time to answer. How do I fix this? Will a WHILE loop work? Or will the program be "stuck" in the WHILE loop and never get to the TCP handler callback?

I'm using LabWindows 5.5.1 on Windows NT 4.0.
Thanks in advance for your help!

--Marianne
0 Kudos
Message 1 of 4
(3,027 Views)
The TCP functions are asynchronous so they will continue like this. What you should do is put a while loop after the TCPWrite that is calling ProcessSystemEvents and is set to drop out of the loop when a flag is set. Then set that flag when you receive the response from the server. So, you code would be:

serverResponded = 0;
ClientTCPWrite(...);
while(!serverResponded)
ProcessSystemEvents();

Then, in when you get a event that the server responded, set the serverResponded flag to 1.

Best Regards,

Chris Matthews
National Instruments
Message 2 of 4
(3,027 Views)
My program works perfectly now! (well, at least as far as the TCP is concerned). Thanks!
--Marianne
0 Kudos
Message 3 of 4
(3,027 Views)
If I put a TCP Read function before a TCP Write function (both in a while loop of the server) and I do the same thing in the client, the performance slows?
0 Kudos
Message 4 of 4
(3,027 Views)