|
Question : TCP vs UDP
|
|
Hi, I think this is an easy question.
I have two linux boxes connected directly to each other. I need to continuously pass data from one two the other. In other words, an interrupt on Box 1 will trigger, a routine will run that will crunch through some data, then it will send that data to Box 2 via ethernet, and Box 2 will do something with that data.
So this is what I need to know (bear with me because my C programming in this area is a little rusty):
1) Should I use TCP or UDP? I am under the impression that to use TCP Box 2 must send a request first, then Box 1 will respond with the data (client/server relationship). Whereas with UDP Box 2 will listen and Box 1 can send the data whenever it wants. If that is indeed the case, then I would prefer to use UDP, although I hear UDP is a lot more reckless than TCP. Any thoughts?
2) I am hoping to pass a float array from Box 1 to Box 2. Is this something I can do, or do I need to convert to char* first?
Thanks,
Isaac
|
Answer : TCP vs UDP
|
|
If the boxes share the same subnet, and if the boxes have a switched connection then it really doesn't matter whether you use TCP or UDP. As far as C programming goes, you can find UPD and TCP connection code on the internet ready to use. Either way, you'll need a client on the receiving box that's listening on a port to accept the inbound data.
The "unreliability" of UDP is a misnomer and really relates ONLY to a comparison of UDP to TCP; UDP, unlike TCP, doesn't provide it's own error correction. But generally, people who choose it for transport add reliability through the application it supports. It is connectionless, but in the real world, most applications that use UDP as a transport either serialize the data or (for example) exchange file check sum data to ensure complete file transfer.
Why not just use FTP? Put an FTP server on the receiving box and be done with it? This will take a lot of the complication out of your code writing chore.
Steve
|
|
|
|