简体   繁体   English

UDP不会丢弃任何数据包

[英]UDP not dropping any packets

I have a C# client and C++ server program that use UDP to communicate. 我有一个使用UDP进行通信的C#客户端和C ++服务器程序。 For now i'm simply using 127.0.0.1 (localhost) to simulate the communication on one machine. 现在,我仅使用127.0.0.1(localhost)在一台计算机上模拟通信。

The problem is that no UDP packets were dropped my 10,000 packet test between the client and server on the same machine, so i don't know how to write the code for retransmission because i can't get it to drop a packet, but it will happen in a real scenario between a client and server on separate machines. 问题是没有UDP数据包在同一台计算机上的客户端和服务器之间的10,000个数据包测试中被丢弃,因此我不知道如何编写代码进行重传,因为我无法使它丢弃数据包,但是它在实际情况下,客户端和服务器在不同计算机上会发生这种情况。

Is it not dropping any packets because the client and server are on the same machine? 是否因为客户端和服务器在同一台计算机上而不丢弃任何数据包?

UDP does not usualy drops packet on same machine. UDP通常不会在同一台计算机上丢弃数据包。 Instead of using rand() function approach you can do another trick. 除了使用rand()函数方法外,您还可以执行其他技巧。 Send large packets from the sender and receive in smaller chunks in the receiver code. 从发送方发送大数据包,并在接收方代码中以较小的块接收。 And use sleep function after every receive. 并在每次接收后使用睡眠功能。 So one the pipe gets full, you may notice packet drops 所以一个管道充满了,您可能会注意到丢包

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM