UDP套接字,Linux两次接收相同的数据 [英] UDP socket, Linux receive the same data twice

查看:204
本文介绍了UDP套接字,Linux两次接收相同的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用UDP套接字将数据从Windows程序传输到Linux上的程序. Linux上的应用程序接收数据,而Windows上的应用程序发送数据.问题是函数recvfrom(...)返回相同的数据2次.因此,我想知道是否有任何设置方法,以便套接字将自动删除从套接字队列中读取的数据? (TCP/IP套接字没有此问题.)

非常感谢,
锡,

Hi everyone,

I am using UDP socket to transmit data from a windows program to a program on Linux. The application on Linux receives data and the application on windows sends data. The problem is the function recvfrom(...) return the same data 2 times. So, I wonder if there is any way to set so that the socket will automatically remove data read from the socket queue? (TCP/IP socket does not have this problem).

Thanks very much,
Tin,

推荐答案

在Wireshark中查看您的网络数据包传输
如果传送了一个数据包,而您又传送了两个数据包,请给我们您的代码以帮助您.
see your network packet transfer in wireshark
if one packet transmitted and you give two packet , please give us your code for helping you.


使用TCP! UDP被设计为不可靠的协议,因此您需要在发送方和接收方中添加一些自己的额外代码,以检查是否存在重复,丢失或乱序消息.
Use TCP! UDP is (designed to be) an unreliable protocol so you need to add some extra code of your own in your sender and receiver to check for duplicate, missing or out of order messages.


这篇关于UDP套接字,Linux两次接收相同的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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