UdpClient无法从DatagramSocket接收

时间:2012-11-19 01:03:07

标签: c# datagram udpclient

我正在申请。服务器端适用于桌面和客户端适用于Windows 8(Metro App- .Net for Windows Store)

这是我的服务器代码:

var udpServer = new UdpClient(7800);
udpServer.BeginRecieve(new AsyncCallback(OnUdpRecieve), null);
. . .
private void OnUdpRecieve(IAsyncResult result)
{
    byte[] data = udpServer.EndReceive(result, ref peerEndPoint);
    udpServer.BeginReceive(new AsyncCallback(OnUdpRecieve), null);
}

这是我在Win RT上的客户端代码:

var udpClient = new DatagramSocket();
await udpClient.ConnectAsync(new HostName("localhost"), 7800);
var udpWriter = new DataWriter(udpClient.OutputStream);
udpWriter.WriteBytes(new byte[] {0, 3, 5});
await udpWriter.StoreAsync();

但在服务器端我没有得到任何东西。我想也许我做错了什么。

由于

1 个答案:

答案 0 :(得分:-1)

我在MSDN论坛上看到了一个问题。这不是我的答案,但有一点是“loclhost”与“127.0.0.1”不同。

当您使用“localhost”时,强制数据报使用IPv4,当您使用“127.0.0.1”时,强制数据报套接字使用IPv6。

这就是重点;)

相关问题