Click here to Skip to main content
15,889,723 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have been programming in C++ since 1989. However, they were in-house programs for GTE. Now, I have a very large project (retired now) that I want to change from Serial to TCP/UDP polling. Far end are RS422 devices that communicate on 4 wires and can be converted to USB virtual ports. Now that I have done that, there is a need to scrap all this and go with IP. There are several converters out there that converts such devices as mine to IP.
Question: what is the best way to poll these devices, TCP or UDP. Mind you, each converter can handle up to 64 devices and my program can handle 4 of these devices (or 4 BUS if serial).
I use 4 threads to poll the serial bus and was thinking the same for IP. I think Threads are more efficient than waiting for a message to be acted upon because its dependent on the OS if its busy or not; threads dont care. The RS422 devices will send a Hex signal asking for a door to be opened and then the computer will send either ok or not. Every minute, the computer will scan the devices to make sure they are still online. So, any of the sides will need to start a communication and the computer must be ready for a reply quickly (<50 msec) to open a door. What does anybody thinks and why? UDP or TCP? or something else?
Thanks in advance

What I have tried:

buying 8 books on the suject by Authors Douglas Schmidt, Stephen D. Huston "ACE Programming", W. Richard Stevens, Douglas E. Comer, and Michael J. Donahoo. Hopefully studying these books and your answers may give me a head start.
Posted
Updated 7-Nov-16 5:59am

1 solution

Well, if you're not sure, TCP/IP should usually be your default go-to. That's because it has a lot of neat built-in overhead that's very useful, such as retransmissions and error checking, that UDP doesn't have. UDP should be used when you need high-speed transmissions where you don't mind occasionally losing packets (VOIP/video and the like).

For example, if you're checking if a device is still online, sending a datagram (UDP) could lead to a lost packet... in which case you wouldn't know if the remote computer even got the packet in the first place (i.e. if it was lost en route). On the other hand, a stream (TCP) would have a handshake process and attempt delivery multiple times before determining that delivery was not possible.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900