How to UDP with Fez Hydra / netMF v4.3?

Hi all,
I’m trying to write a program sending UDP on Fez Hydra, and NetMF v4.3.

Samples I get on code share ( ) and forum are quiet old and they use

using GHIElectronics.NETMF.Net;
using GHIElectronics.NETMF.Net.Sockets;
using GHIElectronics.NETMF.Net.NetworkInformation;

But I can not get them in my code.

Another sample on codeshare :
It uses
using Gadgeteer.SocketInterfaces;
using Gadgeteer.Networking;
using System.Net.Sockets;

But I can not get

How to UDP with Fez Hydra netMF v4.3 ?


@ arnaud.audrezet -

are doing a gadgeteer or MF project?

with a MF project, you need to add the required DLLs to the project references.

it is a gadgeteer project.

I’ve updated my configuration as described in .NET Micro Framework – GHI Electronics to try to improve the situation
[ul]Visual Studio 2013 (I have had to update windows to W10)
NetMF 4.3 QFE2
new core and SDK 2016 R1 etc…[/ul]

The link is interresting but…

I suppose that a key is in this paragraph :
[em]In code, you create what is called a socket. A socket allows communication between your computer and one or more other endpoints (usually remote computers). Sockets can be TCP, UDP, and others. Socket support in NETMF is very similar to the full .NET Framework.
Someone know the rigth url on MSDN ?

I’ve read the proposed code on ghi’ networking page. Compared to it, I can’t use

because '.Net' is not proposed. Why ?

Same problem concerning socket definition...

```cs]using Socket = GHIElectronics.NETMF.Net.Sockets.Socket;[/code

What would be the equivalent ?

Did someone try to UDP with the new SDK ? 


I am using UDP successfully. I am sending UDP packets to a multicast address as a mechanism for a PC to dynamically discover netmf-based controllers.

Here are some relevant snippets

private const string BroadcastAddr = "";
private const int BroadcastPort = 2022;

private void SendAnnouncement()
        IPEndPoint ep = new IPEndPoint(IPAddress.Parse(BroadcastAddr), BroadcastPort);
        using (Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp))
            s.SetSocketOption(SocketOptionLevel.Udp, SocketOptionName.Broadcast, true);
            string controllerId;
            ControllerSettings config = null;
            using (var releaser = _settings.GetExclusiveInstance(out config))
                controllerId = config.identity.controllerId;
            var payload = Encoding.UTF8.GetBytes(controllerId);
            s.SendTo(payload, ep);
        // failures here are never fatal
        //TODO: though we should log them

@ arnaud.audrezet - You know how “using” statements work, right? You first add a reference to the appropriate DLL in the Solution Explorer “References” section, then you will be able to add a Using statement and have auto-complete see the correct reference. And you can use Object Browser to see “into” those references you add to see what namespaces are there?

System.Net is in the “System” reference. Ensure you add that, and you will be able to see the System.Net and System.Net.Sockets namespaces.

1 Like

I see now that I offered a very reasonable answer to completely the wrong question. Oooops. Seems to be just a ref problem and Brett put forth a fine answer.

No, I don’t know how references section works…, I’ve already ‘solved’ a problem with reference section one year ago but it was not clear for me.
Ok, when I add ‘System’ to the references, autocompletion propose “.net.Socket”. I’ll continue later.

(Im’ surprised to see that System.Collections/.text… are working without System in reference section…).

Thank you again Brett, and thank you mcalsyn, I’m sure your example will be usefull for me.


@ arnaud.audrezet - one little trick is that there’s not always a 1:1 relationship between a reference (dll) and a namespace. I’d suggest you right click on a reference and say view in object browser, to explore what namespaces exist in what references. You’ll find that System.Collections and System.Text are in the “mscorlib”, the core "system"framework component - along with System.IO, and a whole heap of others.

Ok thank you Brett ! I see, I understand, I improve !

Thank you so much,

1 Like