[英]UDP Socket returns part of packet
Info:Im working on a VOIP application. 信息:我正在开发VOIP应用程序。
Im using the C# Socket class and initalize it as a UDP socket. 我使用C#套接字类并将其初始化为UDP套接字。
My code for receiving: 我的接收代码:
if(socket.Poll(-1,SelectMode.SelectRead)){
if(!socket.Connected){
return;
}
Console.WriteLine(" AVAIL:"+socket.Available);
int count = socket.ReceiveFrom (data, ref endpoint);
Console.WriteLine("LENGTH:"+count);
receivedEvent.Reuse (socket, data, count, (IPEndPoint)endpoint);
receivedFunction (receivedEvent);
}
My code for sending: 我的发送代码:
int cnt = socket.SendTo (data, length, SocketFlags.None, ep);
if (cnt != length) {
//LOG STUFF
}
if (sendEvent != null) {
sendEvent (cnt);
}
ERROR: I get unexpected data from my udp socket, meaning im sending ~100 bytes of data but I only receive 31. Which is just wrong => I thought UDP will always give me all or nothing. 错误:我从udp套接字中获得了意外数据,这意味着我正在发送〜100字节的数据,但我只收到31。这是错误的=>我以为UDP总是会给我带来全部或全部的收益。 Am I wrong ?
我错了吗 ?
So my question is, shouldn't UDP be reliable in sense of packets ? 所以我的问题是,UDP是否在数据包意义上不可靠? Like I only should get valid or none packets ?
像我只应该获取有效数据包还是不获取数据包?
Another problem I seem to have (not sure if it is connected to my current issue?), after ~30 minutes my socket only returns 10 as count of data read from socket. 我似乎遇到的另一个问题(不确定是否已连接到当前问题吗?),大约30分钟后,我的套接字仅返回10作为从套接字读取的数据计数。
So my question is, shouldn't UDP be reliable in sense of packets ?
所以我的问题是,UDP是否在数据包意义上不可靠? Like I only should get valid or none packets ?
像我只应该获取有效数据包还是不获取数据包?
no unless you use UDP checksums, do you use raw sockets ? 否,除非您使用UDP校验和,否则是否使用原始套接字?
ERROR: I get unexpected data from my udp socket, meaning im sending ~100 bytes of data but I only receive 31. Which is just wrong => I thought UDP will always give me all or nothing.
错误:我从udp套接字中获得了意外数据,这意味着我正在发送〜100字节的数据,但我只收到31。这是错误的=>我以为UDP总是会给我带来全部或全部的收益。 Am I wrong ?
我错了吗 ?
Did you deactivate the IP fragmentation ? 您是否停用了IP分段? https://msdn.microsoft.com/en-us/library/system.net.sockets.udpclient.dontfragment%28v=vs.110%29.aspx
https://msdn.microsoft.com/zh-cn/library/system.net.sockets.udpclient.dontfragment%28v=vs.110%29.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.