LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with "TCP write"

Hello,

I have the following problem in LabVIEW 7.1: I use "TCP write" to send a stream through an open connection. Immediately after, I use "TCP close connection". Well, the other party sometimes receives the stream and sometimes it doesn't. Is it possible that the connection is being closed before the message is actually sent? How should I get around this problem? Should there be some sort of delay between the write and the close? Thanks in advance for any suggestions.
0 Kudos
Message 1 of 9
(2,634 Views)
Make sure your dataflow is correct.  Are you using the error in and out to guide the flow of your program?

Maybe this could be why the close is happening before the write
- James

Using LV 2012 on Windows 7 64 bit
0 Kudos
Message 2 of 9
(2,631 Views)
Yes, the dataflow is correct. The connection ID comming out of "TCP write" goes into "TCP close connection". I am only speculating that the connection might be closed before the write operation is actually done. I don't know this for sure. What I do know is that when I do read and write through a connection that remains open, everything is OK, but if I write and then close the connection immediately after, the other end sometimes gets the message, and sometimes doesn't.
0 Kudos
Message 3 of 9
(2,629 Views)
can you attach your code? or just the portion that you are describing
- James

Using LV 2012 on Windows 7 64 bit
0 Kudos
Message 4 of 9
(2,624 Views)
OK, I'm attaching a test. There are two VIs, one is the client and one is the server. You can run both on the same machine. First execute the server and then the client. If everything goes well, the server should receive the string "hello". Do this several times and you'll see that sometimes the server doesn't receive the message.
Download All
0 Kudos
Message 5 of 9
(2,618 Views)
I have not been able to reproduce the problem that you are describing

but a couple of notes about your design

1   the while loop in your server program is unnecessary the way this example is written.
    your listener will wait indefinetly until it gets a connection but your client only runs once then closes the connection therefore the server while loop will only run once then exit on error
2   Try not to use sequence structures and local variables unless they are necessary
    the 0 sequence is not necessary along with the local variable
    to acomplish the same result as a sequence use subvi's with error clusters to control the flow
3   sometimes localhost acts differently than two separate computers regarding timeouts and connections (in my experience anyway)
4   unless you have special circumstances regarding closing the connection I suggest leaving it open until the main vi closes.
5   if you want to only make the connection once and have the server vi stay listening try putting the entire server program in a while loop adding shift registers to the error tunnels and converting connection errors to warnings
- James

Using LV 2012 on Windows 7 64 bit
0 Kudos
Message 6 of 9
(2,612 Views)
Thanks James for taking the time to help. So you ran the server.vi and client.vi a bunch of times and you never found the problem I'm describing? When I performed that test repeatedly, I found that the problem happened about 1 out of every 10 times.
0 Kudos
Message 7 of 9
(2,608 Views)
I tried many many times and not able to reproduce

Although i am testing on labview 8.01 on linux.   I will try on windows also and let you know
- James

Using LV 2012 on Windows 7 64 bit
0 Kudos
Message 8 of 9
(2,604 Views)
I also tried a bunch on windows with 8.0.1 on a different machine and still was not able to reproduce it
 
the windows machine has xp installed with sp2 512mb RAM P4 2.66GHz

Message Edited by James R on 04-04-2007 03:51 PM

- James

Using LV 2012 on Windows 7 64 bit
0 Kudos
Message 9 of 9
(2,598 Views)