I am having the following problem:
I am communicating 2 different machines in local network with UDP.
In one side I have a Windows 7 machine with 4.5 framework installed. I am using the class System.Net
with this code:
public static void UDPWriter()
{
Task.Run(async () =>
{
byte[] data = new byte[10000];
IPEndPoint ipep = new IPEndPoint(IPAddress.Pars("192.168.0.16"), 5002);
Socket udpClient = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
udpClient.Connect(ipep);
while (true)
{
await Task.Delay(24);
string input = packagetosend;
data = Encoding.ASCII.GetBytes(input);
var receivedResults = udpClient.Send(data, SocketFlags.None);
}
});
}
In the other side I am working with a Windows 10 Universal App with this code:
async static private void EnablerListener()
{
//Click
HostName hostname = new HostName("192.168.0.16");
listener = new DatagramSocket();
listener.Control.InboundBufferSizeInBytes=10000;
listener.MessageReceived += socket_MessageReceived;
await listener.BindServiceNameAsync("5002");
}
static void socket_MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
{
// Message received. Place your logic here
}
As soon as I send a "small" package ( my theory is that less than the MTU) I receive correctly what is sent.
The problem comes with I my udp package is fragmented. When I send 1 packages that is splitted in 4 ( I have seen it in Wireshark) the Windows 10 software do not receive anything. I have tried changing listener.Control.Donotfragment( maybe I am using it wrong) but it seems not working.
UPDATE1:
In wireshark I receive this message
time-to-live exceeded (fragment reassembly time exceeded) Only some packages in Wireshark, others are succesfully reassembled ( almost all)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…