informed
Posts: 128
Joined: Mon Oct 26, 2015 6:24 pm

UDP not being recieved

Thu Jan 14, 2016 7:15 am

Hi,

In my Raspberry Pi2 device I have an app that broadcasts its own IP address (on a timer) to the rest of my network this that code:

public static async Task SendMessage(string message, int port)
{
try
{
var socket = new DatagramSocket();

//socket.MessageReceived += SocketOnMessageReceived;

using (var stream = await socket.GetOutputStreamAsync(new HostName("255.255.255.255"), port.ToString()))
{
using (var writer = new DataWriter(stream))
{
var data = Encoding.UTF8.GetBytes(message);

writer.WriteBytes(data);
await writer.StoreAsync();
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex, "SocketClient.InitSoSendcketClient");
}
}

On my client app it will pick it up via this code:

public static void Start()
{

UdpClient udpServer = new UdpClient(80);
var remoteEP = new IPEndPoint(IPAddress.Any, 80);

while (true)
{
var data = udpServer.Receive(ref remoteEP);
var requestCommand = Uri.UnescapeDataString(Encoding.UTF8.GetString(data, 0, data.Length));
var message = JsonConvert.DeserializeObject<Model.NotifyMessage>(requestCommand);
Shared.RASPBERRY_PI_IP_ADDRESS = message.IP;
Console.WriteLine(message.IP);
}
}

This used to work but does not do so now. I had upgraded the Raspberry PI2 'OS' to the latest but I seem to recall it still worked for a while.

It just stopped working yesterday for some reason. I have set the breakpoints and I know the IP address is being sent from the PI it is just not being recieved for some reason.

Is it a virus? Is it a firewall issue on the PI (if so how do I let it through?)?

I can still browse to the home page OK and my Windows IoT Core Watcher still sees the device

ricl
Posts: 657
Joined: Wed Aug 26, 2015 11:55 am

Re: UDP not being recieved

Thu Jan 14, 2016 8:50 am

Make sure you have opened the relevant port in the Pi's Firewall. It is in the FAQ.
ricl : F/gamma = ma : Law ii(a) : https://climatedatablog.wordpress.com/2016/01/02/an-energy-challenge-2016/ #AnEnergyChallenge2016

haroulis
Posts: 2
Joined: Thu Jul 13, 2017 3:01 pm

Re: UDP not being recieved

Thu Jul 13, 2017 4:08 pm

informed wrote:Hi,

In my Raspberry Pi2 device I have an app that broadcasts its own IP address (on a timer) to the rest of my network this that code:

public static async Task SendMessage(string message, int port)
{
try
{
var socket = new DatagramSocket();

//socket.MessageReceived += SocketOnMessageReceived;

using (var stream = await socket.GetOutputStreamAsync(new HostName("255.255.255.255"), port.ToString()))
{
using (var writer = new DataWriter(stream))
{
var data = Encoding.UTF8.GetBytes(message);

writer.WriteBytes(data);
await writer.StoreAsync();
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex, "SocketClient.InitSoSendcketClient");
}
}

On my client app it will pick it up via this code:

public static void Start()
{

UdpClient udpServer = new UdpClient(80);
var remoteEP = new IPEndPoint(IPAddress.Any, 80);

while (true)
{
var data = udpServer.Receive(ref remoteEP);
var requestCommand = Uri.UnescapeDataString(Encoding.UTF8.GetString(data, 0, data.Length));
var message = JsonConvert.DeserializeObject<Model.NotifyMessage>(requestCommand);
Shared.RASPBERRY_PI_IP_ADDRESS = message.IP;
Console.WriteLine(message.IP);
}
}

This used to work but does not do so now. I had upgraded the Raspberry PI2 'OS' to the latest but I seem to recall it still worked for a while.

It just stopped working yesterday for some reason. I have set the breakpoints and I know the IP address is being sent from the PI it is just not being recieved for some reason.

Is it a virus? Is it a firewall issue on the PI (if so how do I let it through?)?

I can still browse to the home page OK and my Windows IoT Core Watcher still sees the device

What language is your code? did you manage to make it work?

KyysmaWen
Posts: 6
Joined: Mon May 15, 2017 12:57 pm
Location: Россия

UDP not being recieved

Thu Aug 03, 2017 2:22 pm

hers your problem

try un-checking some codecs

tools>options>compatibility tab

Return to “Windows 10 for IoT”