Windows 10中的UDP问题。UWP [英] Problems with UDP in windows 10. UWP
问题描述
我遇到以下问题:
我正在使用UDP与本地网络中的2台不同计算机进行通信。
在一侧,我有一台Windows 7计算机安装了4.5框架。我正在使用带有以下代码的类System.Net
:
public static void UDPWriter()
{
Task.Run(async()=>
{
byte [] data = new byte [10000];
IPEndPoint ipep =新IPEndPoint(IPAddress.Pars( 192.168.0.16),5002);
套接字udpClient =新Socket(AddressFamily.InterNetwork,SocketType.Dgram,ProtocolType.Udp);
udpClient.Connect(ipep);
而(true)
{
等待Task.Delay(24);
字符串输入= packagetosend;
数据= Encoding.ASCII.GetBytes(输入);
var receiveResults = udpClient.Send(数据,SocketFlags.None);
}
});
}
另一方面,我正在使用Windows 10 Universal带有以下代码的应用:
异步静态私有无效EnablerListener()
{
//单击
HostName主机名=新的HostName( 192.168.0.16);
listener = new DatagramSocket();
listener.Control.InboundBufferSizeInBytes = 10000;
listener.MessageReceived + = socket_MessageReceived;
等待监听器。BindServiceNameAsync( 5002);
}
static void socket_MessageReceived(DatagramSocket sender,DatagramSocketMessageReceivedEventArgs args)
{
//收到消息。将您的逻辑放在这里
}
(我的理论是,比MTU少)我正确地收到了发送的邮件。
问题来自于我的udp软件包是零散的。当我发送1个分成4个的软件包(我在Wireshark中看到过)时,Windows 10软件什么也收不到。我曾尝试更改listener.Control.Donotfragment(也许我使用的是错误的),但它似乎无法正常工作。
UPDATE1:
在wireshark中,我收到以下消息:
超过了生存时间(超过了碎片重组的时间)仅在Wireshark中有一些软件包,有的则被成功地重组了(几乎所有)
在UWP上使用环回的本地计算机IPC受限制。我最近遇到了这个问题。也许考虑使用不同的方法,例如应用程序间通信- https:// channel9。 msdn.com/Events/Build/2015/3-765
来自DatagramSocket示例:
<注意,使用IP回送地址的网络通信通常不能用于通用
Windows平台(UWP)应用程序与其他进程(不同的UWP
应用程序或桌面应用程序),因为这受到网络隔离的限制。
在
内允许使用IP环回地址进行网络通信,出于UWP应用中的通信目的,该过程相同。有关
的更多信息,请参见如何设置网络功能。
https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/DatagramSocket (朝底部)
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)
Local machine IPC using Loopback on UWP is restricted. I recently ran in to this problem myself. Perhaps consider a different approach like App-to-App Communication - https://channel9.msdn.com/Events/Build/2015/3-765
From the DatagramSocket sample:
Note Network communications using an IP loopback address cannot normally be used for interprocess communication between a Universal Windows Platform (UWP) app and a different process (a different UWP app or a desktop app) because this is restricted by network isolation. Network communication using an IP loopback address is allowed within the same process for communication purposes in a UWP app. For more information, see How to set network capabilities.
https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/DatagramSocket (towards the bottom)
这篇关于Windows 10中的UDP问题。UWP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!