UDP Listener XP / Vista / Win7的区别?

时间:2009-11-03 12:06:42

标签: c# udp

我在我的桌面上开发了一些运行Windows 7的软件,该软件似乎运行正常。该软件似乎也适用于我们的Vista笔记本电脑。但是我在使用XP时遇到了一些问题。

该软件以一个发现工具开始,该工具在端口46787上发送UDP广播消息,并侦听来自同一端口上的设备的回复。这适用于所有三个操作系统。

一旦选择了已发现的设备,就会停止发现UDP cient。然后在端口46788上启动另一个UDP客户端以侦听来自设备的数据:

            receiverUDP = new UdpClient("255.255.255.255", 46788);
            receiverUDP.EnableBroadcast = true;

            // Start receiving Async UDP packets
            receiverUDP.BeginReceive(new AsyncCallback(ReceiveUDP), receiverUDP);

在XP上,当调用EndReceive时会抛出一个System.Net.Sockets.SocketException,但它在Vista / Win7中完美运行,我将数据流传输到...

System.Net.Sockets.SocketException: The I/O operation has been aborted because of either a thread exit or an application request
   at System.Net.Sockets.Socket.EndReceiveFrom(IAsyncResult asyncResult, EndPoint& endPoint)
   at System.Net.Sockets.UdpClient.EndReceive(IAsyncResult asyncResult, IPEndPoint& remoteEP)
   at Demo.IOPanel.ReceiveUDP(IAsyncResult result) in C:\...\IOPanel.cs:line 262
   at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
   at System.Net.ContextAwareResult.CompleteCallback(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Net.ContextAwareResult.Complete(IntPtr userToken)
   at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
   at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
   at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

禁用Windows防火墙,没有安装其他防火墙。我已经使用netstat进行了检查,其他任何东西都没有使用该端口。我已经尝试了5个其他随机端口,它仍然无法正常工作。

我知道堆栈是完全为Vista重写的,所以什么改变了?不应该.Net隐藏所有这些差异吗?

1 个答案:

答案 0 :(得分:2)

调用BeginReceive的线程是否可能在某个时刻终止?这适用于Vista但不适用于XP;请参阅此related question以及接受的答案的评论。