什么是C ++中最好的IP解决方案 [英] What is the best IP solution in C++

查看:136
本文介绍了什么是C ++中最好的IP解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自1989年以来,我一直使用C ++进行编程.但是,它们是GTE的内部程序.现在,我有一个非常大的项目(现已退休),我想从串行轮询更改为TCP/UDP轮询.远端是RS422设备,可通过4条线进行通信,并且可以转换为USB虚拟端口.既然我已经做到了,那么就需要废弃所有这些并使用IP.那里有几个转换器,可将诸如我的设备转换为IP.
问题:轮询这些设备(TCP或UDP)的最佳方法是什么.请注意,每个转换器最多可以处理64个设备,而我的程序可以处理这些设备中的4个(如果是串行,则可以处理4个BUS).
我使用4个线程轮询串行总线,并且在IP方面也是如此.我认为线程比等待消息更有效,因为无论是否忙,线程都依赖于操作系统.线程不在乎. RS422设备将发送一个Hex信号,要求打开一扇门,然后计算机将发送ok或不行.每分钟,计算机将扫描设备以确保它们仍处于联机状态.因此,任何一方都将需要开始通信,并且计算机必须准备好快速(<50毫秒)答复才能打开门.有人在想什么,为什么? UDP或TCP?还是其他?
在此先感谢

我尝试过的事情:

购买了8本关于主题的书,作者是道格拉斯·施密特(Douglas Schmidt),斯蒂芬·休斯顿(Stephen D. Huston)"ACE编程",理查德·史蒂文斯(W. Richard Stevens),道格拉斯·E·科默(Douglas E. Comer)和迈克尔·多纳胡(Michael J. Donahoo).希望学习这些书,您的答案可能会给我一个很好的开端.

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.

推荐答案

好吧,如果您不确定,通常应将TCP/IP作为您的默认选择-到.那是因为它有很多整洁的内置开销,这非常有用,例如UDP所没有的重传和错误检查.当需要高速传输而又不介意偶尔丢失数据包(VOIP/视频等)时,应使用UDP.

例如,如果您要检查设备是否仍在线,则发送数据报(UDP)可能会导致数据包丢失……在这种情况下,您将不知道远程计算机是否甚至将数据包放入了计算机中.第一名(即如果途中丢失).另一方面,流(TCP)将具有握手过程,并在确定无法进行传递之前尝试多次传递.
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.


这篇关于什么是C ++中最好的IP解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆