LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sending a result data of a While loop via another while loop of TCP communication

Solved!
Go to solution
Hi Crossrulz,
1. I will try again. Thank you!
2. There is no better way to stop both loops immediately? It's not good to wait 2 mins to stop the program 😞
0 Kudos
Message 11 of 17
(1,591 Views)

Hi Crossrulz,

1. It runs properly now.

2. I set the timeout of the 2 TCP Read 50ms, but Stop Button still did not work. And if I press Stop button once, then start the program again, the VI is extremely slow. I have to close the VI then open again to make it work.

3. If I close the client first, I always get an error 1 from the TCP read. How to fix it?

0 Kudos
Message 12 of 17
(1,561 Views)
Solution
Accepted by topic author Bestest_boy

@Bestest_boy wrote:

3. If I close the client first, I always get an error 1 from the TCP read. How to fix it?


A TCP connection is a two way street.  If the client closes the connection, then the server will get the error.

 

What you really need to do is make your TCP loop a state machine.  Have a state for making a connection, waiting for a message, sending the data, and closing your connection.  The idea here is that you start by setting up a connection.  Once a connection is established, you go to the wait state.  If you get a connection error in the wait state, you should close your connection reference and then go back to making a connection.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 13 of 17
(1,544 Views)

Hi Crossrulz,

I made a state machine for TCP loop already and it worked. However I caught a problem with the Stop signal.

- My Client is fixed and I cannot change the way it gets and sends data.

- In my VI server, Stop button is checked to go to Stop state. In the case Stop, I close the TCP connection and stop all the loops. And I got problem here. If the Client close first, the TCP refnum is 0 and this becomes an invalid input for the input of TCP Close Connection. Everything is OK if I close the server first.

Do you have any idea to solve this problem?

Attached is my VI.

0 Kudos
Message 14 of 17
(1,452 Views)
Solution
Accepted by topic author Bestest_boy

If the TCP Refnum is consitently changing to 0 on client disconnect, you could monitor the refnum and exit into a shutdown state when that is seen. You can also monitor for error codes 62, 64, 66 which are:

"The system caused the network connection to be aborted", "The network connection is not yet established", and "The network connection was closed by the peer" errors, respectivley. 

Message 15 of 17
(1,423 Views)
Hi Samazing,
What will I do in the Shut down state? Close connection or something else? But with refnum 0, I cannot use TCP Close Connection.
The same with error codes monitoring. When I get 66, what will I do?
0 Kudos
Message 16 of 17
(1,415 Views)
Solution
Accepted by topic author Bestest_boy

@Bestest_boy wrote:
What will I do in the Shut down state? Close connection or something else? But with refnum 0, I cannot use TCP Close Connection.
The same with error codes monitoring. When I get 66, what will I do?

In the shutdown, just use Clear Error to clear error 66.  Obviously, if the connection was already closed, you cannot close it again.  That is nothing to worry about during the shutdown.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 17 of 17
(1,395 Views)