DatagramSocket 事件 MessageReceived 不触发 [英] DatagramSocket event MessageReceived dosen't trigger

查看:27
本文介绍了DatagramSocket 事件 MessageReceived 不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于 System.Net.Sockets UdpClient 的控制台 Udp 服务器,我从中发送 Udp 数据包到我的 Windows Phone 8.1 的 Ip.

手机客户端使用的是Windows.Networking.Sockets DatagramSocket,我的问题是没有发生MessageReceived事件.

DatagramSocket 的来源:https://msdn.microsoft.com/library/windows/应用程序/br241319

解决方案

我花了很长时间才找到解决方案,因为它非常愚蠢:DatagramSocket 只在发送了一些东西后才开始接收.(至少对于广播消息.)

一些代码:https://gist.github.com/michaelosthege/857acac92b8eb30d9f6/p>

I have a Console Udp Server based on the System.Net.Sockets UdpClient from which I'm sending Udp Packets to the Ip of my Windows Phone 8.1.

The client on the phone uses Windows.Networking.Sockets DatagramSocket, my problem is that the event MessageReceived dosen't happen.

Source for DatagramSocket:https://msdn.microsoft.com/library/windows/apps/br241319

解决方案

Took me ages to find the solution since it's pretty dumb: The DatagramSocket only starts to receive after it has sent something. (At least for broadcast messages.)

Some code: https://gist.github.com/michaelosthege/857acac92b8ee689a6bb30d5bf23d9f6

这篇关于DatagramSocket 事件 MessageReceived 不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆