Lowest Latency small size data Internet transfer protocol? c#

只愿长相守 提交于 2019-12-02 05:47:10

问题


I am doing a Internet Gaming project which involving keeping sending small size of data (between 1K to 50K) over the Internet between two normal home PCs. The key I care about is the latency.

I understand TCP, UDP are the popular ones. TCP is reliable but slower than UDP while UDP is not safe and I have to implement my own fault-handling codes.

I am just wondering are there any other protocols I can follow to send/receive small data between two normal home PCs?

by the term of normal home PCs, I assume that they have normal broadband (512kbps - 2Mkbps) and all around the world (maybe between US and Japan).

Another BIG question is that:

If I ping from one pc (in UK) to another (in Japan), I get 300ms latency. Is that possible to find one protocol or use TCP/UDP to send/receive 1KB data below this 300ms latency?? or ping should be the fastest way to know the lowest latency between two end points??

Thanks


回答1:


A TCP header is 32 bytes, while a UDP header is only 16 bytes. In addition, since UDP lacks flow control there will never be a case where the client asks the server to slow down. UDP is almost definitely going to be the fastest. An ICMP packet has a header that is 20 bytes, and is probably going to be slightly slower than UDP.

My official recommendation is to use UDP, with some "dropped packet" detection at the receiving end. This is how all of the Quake games and all of the Half-Life/Source games work.

On the topic of pinging between UK and Japan, the latency is going to be near identical for any protocol used. Most of that is dictated by the speed of light and the congestion of the edge-routers.




回答2:


You will never beat ping commands for latency, since they use ICMP, which is about the most lightweight option out there.

Typically, for gaming situations, UDP is used, primarily because of the speed involved. With a good broadband connection, TCP should be fine, and will make life easier since you have guarantees about delivery that are otherwise missing from UDP.

That being said, for gaming purposes, 1K, and especially 50K, is a very large amount of data, especially if this needs to be sent continuously. If you're sending that much data, expect and plan for the latency - often this means anticipating what will happen across the wire, and compensating when the data comes through, instead of waiting on the data to arrive.




回答3:


If you want to communicate over the Internet you are forced to use IP family of protocols. That doesn't prevent you from creating your own protocol on top of IP, but it won't be faster in terms of latency, of course. All you can do is implement compression in order to minimize payload sent over the wire.



来源:https://stackoverflow.com/questions/2290873/lowest-latency-small-size-data-internet-transfer-protocol-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!