Showing results for 
Search instead for 
Did you mean: 

Send binary files using TCP

Go to solution


I`d like to send binary files from a PC to another one using TCP/IP  server program.

The name of the file I want to send is the number from 0 ~ n and send from 0 to n  every 10 msecs.

I attached the server VI and Wireshark analysis  below.

Wireshark analysis showed the program send same 2 packet  after made  connection and then program close tcp connection after send 2 packets  and reconnecting again.

What is the problem with my server program?

Could I have your help?

Thank you.

Download All
0 Kudos
Message 1 of 3
Accepted by Torachan

Well, This is what you're doing:


1) The loop on the left will bring one CPU to it's knees. At least put a wait in there. But an event structure with value change event does almost the same...


2) You're getting the size of the directory. Then in the loops build the file paths. Why not use List Folder to get a list of files in the directory? Save's you the hassle in the loop...


3) After waiting for a listener (client), you send the same package yourself twice.


4) Then you wait 100 ms for one byte from the client, and clear the error if it has timed out.


5) Then you close the connection yourself.


So, you wait for client, send the first file twice, and close the connection.


You describe this as the problem, but it is exactly what you've made. It does exactly what you describe, as expected. We can't get from what you made what you expect it to do.


If you only want to write the file once, delete the second write.


If you don't want to open\close between each file, put the wait for listener and close outside the for loop. You'd need to add the length of the files, or you'll have no way on the client to split those files...

0 Kudos
Message 2 of 3

One of the Bane of Programmers is that "My Code Does What I Tell It To Do, Not What I Want It To Do".  I've been know to comment that "Looking at your code, I have no idea what you want to do, but I can certainly see how you are doing it, even if I don't understand it".


Here are some "relevant" and "irrelevant" pieces from your initial description:

  • I want to send Binary Files from one PC to another (relevant).
  • ... using TCP/IP Server Program (irrelevant, says "how", worry about this later).
  • The name of the file I want to send is ... (irrelevant, though it is relevant that you know the name of the file).
  • ... and send from 0 to n every 10 msec (confusing!).  You clearly want to do something 100 times a second, but it isn't clear if you are sending a single specific file or multiple files ("from 0 to n"), and if n is large, this can be a problem, depending on transmission speed.
  • You don't say, but I suspect that the receiver is supposed to create files having the same name as the file being sent, so you need to send both the file name and file data.

So a "high-level view" might go something like this:

  1. Establish communication channel between Host and Remote ("Server").
  2. When ready, start sending files from Host to Remote.
    1. File name to send determined by Host according to some algorithm.
    2. Host sends a file at specified interval or on some specified condition.
    3. Remote receives file and does something appropriate with the data (like save to disk).
  3. When all data are sent, close communication channel.

I recommend using LabVIEW's Network Streams for this task, as it takes some of the details/drudgery out of the picture.


Bob Schor

0 Kudos
Message 3 of 3