如何使用UDP协议顺序获取数据包?

发布于 2024-12-27 07:40:58 字数 358 浏览 2 评论 0原文

我正在用 c# 制作应用程序。我不断在 24097 端口上获取数据,并将该数据记录为

UdpClient client = null;
 IPEndPoint ipep = null;
 client = new UdpClient(24097); 
 client.Client.ReceiveBufferSize = 25000;
 ipep = new IPEndPoint(IPAddress.Any,24097);
while(flag)
{
  byte[] data= = client.Receive(ref ipep);
}

但我的问题是我收到的任何数据包都不是按顺序排列的。我想按顺序接收它们。请帮助我。提前致谢。

I am making application in c#. I am getting data on 24097 port continuously and i am recording that data as

UdpClient client = null;
 IPEndPoint ipep = null;
 client = new UdpClient(24097); 
 client.Client.ReceiveBufferSize = 25000;
 ipep = new IPEndPoint(IPAddress.Any,24097);
while(flag)
{
  byte[] data= = client.Receive(ref ipep);
}

But my problem is whatever packets i am getting are not in sequential order. I want to receive them in sequential manner. Please help me.Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情话墙 2025-01-03 07:40:58

UDP 不保证您发送的数据的顺序。这是“一劳永逸”。如果需要将数据保存在有序流中,则需要使用 TCP。

否则,您需要在数据报本身中实现某种序列 ID。

UDP does not guarantee anything about the order of the data you send. It is "fire and forget". If you need to keep the data in an ordered stream, you need to use TCP.

Otherwise, you would need to implement some sort of sequence ID in your datagrams themselves.

三人与歌 2025-01-03 07:40:58

此链接可能会有所帮助

http://www.codeproject.com/Articles/176722/Sending-messages-to-workstations-using-Socket-Prog/?display=PrintAll&fid=1618703&df=90&mpp=25& ;noise=3&prof=False&sort=Position&view=Quick

该样本有 2 部分。
第一个是发送者(在某些电脑中),另一个是接收者(在客户端电脑中)。
发送方中提到的端口应与接收方中的端口相同。

发送者应用程序中有一个文本框和按钮(发送)按钮。
在各自的 PC 上运行这两个项目。

单击发送器中的“发送”按钮后,文本框中的数据将按顺序发送到接收器。

希望它有一些用处。谢谢。

This link might help

http://www.codeproject.com/Articles/176722/Sending-messages-to-workstations-using-Socket-Prog/?display=PrintAll&fid=1618703&df=90&mpp=25&noise=3&prof=False&sort=Position&view=Quick

This sample has 2 parts.
First one is the sender(in some pc) and the other one is the receiver(in client pc).
Port mentioned in the sender should be same as the one in the receiver.

there is a text box and button(Send) button in the sender application.
Run both the projects in the respective PCs.

On clicking Send button in the sender, data from the text box will be sent sequentially to the receiver.

Hope it is of some use. Thank you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文