0

I am working on a project which requires sensor information to be obtained from multiple embedded devices so that it may be used by a master machine. The master currently has classes which contain backing fields for each sensor. Data is continuously read on each sensor and a packet is then written and sent to the master to update that sensor's backing field. I have little experience with TCP/UDP so I am not sure which protocol would work better with this setup.

I am currently using TCP to transfer the data because I am worried about data on our rotary encoders being received out of order. Since my experience with this topic is limited, I am not sure if this is this a valid concern.

Does anyone with experience in this area know any reasons that I should prefer one approach over the other?

4

2 回答 2

1
  • 你有多在乎知道一个数据包已经送达了?
  • 您有多在乎是否知道交付的数据包是 100% 正确的?
  • 您有多在意数据包传递的顺序?
  • 您对当前连接的对等点有多关心?

如果答案是“我很在乎”,那么您更愿意继续使用 TCP,因为它可以确保所有四点。

对应的是,如果您管理小数据包,UDP 可以更轻量级和更快地处理。

无论如何,选择这个或那个并不容易。试试看嘛。

并阅读这个简短的解释:http ://www.cyberciti.biz/faq/key-differences-between-tcp-and-udp-protocols/

于 2013-01-09T15:22:46.493 回答
0

我不是专家,但似乎这可能是相关的:

你可以丢失数据吗?

如果是这样,请使用 TCP。错误恢复是自动的。

如果没有,请使用 UDP。丢失的数据包不会重新发送。我也相信不能保证在这里订购。

于 2013-01-09T15:19:38.637 回答