积极答复者
DatagramSocketa在收到ICMP数据包的时候会停止工作

问题
-
我们的项目中有一个windows runtime component子工程,该工程用到了DatagramSocket, 这个socket负责数据的收发工作。
接收部分调用的是BindServiceNameAsync(),而且注册了MessageReceived 回调函数。发送部分使用的是GetOutputStreamAsync,和WriteAsync。
现在的问题是,如果本机收到ICMP数据包(Port unreachable), MessageReceived回调函数就会停止收数据, 而且我用try catch有时候可以收到SocketErrorStatus::ConnectionResetByPeer异常,有时候就收不到。
这个问题有办法解决吗,或者有没有其他的方式来处理udp的收发。
MessageReceive回调是这样写的:
void CUDPBaseProcessor::OnMessage(DatagramSocket^ socket, DatagramSocketMessageReceivedEventArgs^ eventArguments)
{
try
{// do work
}
catch (Exception^ exception)
{
SocketErrorStatus socketError = SocketError::GetStatus(exception->HResult);
if (socketError == SocketErrorStatus::ConnectionResetByPeer)
{
// This error would indicate that a previous send operation resulted in an ICMP "Port Unreachable" message.
}
}}
答案
-
Hi,
你的邮件我已经收到了,虽然我没有重现问题,但是我找到了关于ICMP的官方解释:
http://social.msdn.microsoft.com/Forums/en-US/tailoringappsfordevices/thread/41aa79e3-270e-4cb1-9a66-0aad953fb0c9
DatagramSocket没有办法接受到ICMP报文。
我希望能够为你找到一个解决方案,但是发现.Net库的Socket不支持并且,C++中winsock2.h中发现了#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)防止了这个头文件在WinRT环境下编译。
因此我找不到任何办法在WinRT实现这个。只能够比如写一个桌面然后通过这个发送通知到商店应用中,你可以参考:
http://msdn.microsoft.com/en-us/library/windows/apps/hh779727.aspx
里面的Sending notification from destop
Aaron
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已标记为答案 Aaron XueModerator 2013年2月5日 13:57
全部回复
-
Hi,
这个具体是什么时候会发生这个问题呢?有重现的步骤吗?看你的描述我认为你的代码没有问题。这个是在连接服务器端的端口的时候无法连接会出现这种问题吗?
Aaron
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help. -
Hi,
你的邮件我已经收到了,虽然我没有重现问题,但是我找到了关于ICMP的官方解释:
http://social.msdn.microsoft.com/Forums/en-US/tailoringappsfordevices/thread/41aa79e3-270e-4cb1-9a66-0aad953fb0c9
DatagramSocket没有办法接受到ICMP报文。
我希望能够为你找到一个解决方案,但是发现.Net库的Socket不支持并且,C++中winsock2.h中发现了#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)防止了这个头文件在WinRT环境下编译。
因此我找不到任何办法在WinRT实现这个。只能够比如写一个桌面然后通过这个发送通知到商店应用中,你可以参考:
http://msdn.microsoft.com/en-us/library/windows/apps/hh779727.aspx
里面的Sending notification from destop
Aaron
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已标记为答案 Aaron XueModerator 2013年2月5日 13:57