W5100 udp

Is UDP on the plans for the final release, or just TCP to start?

I thought UDP is already supported :o

Brett,

Socket tcpSocket = new _
    Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

Socket udpSocket = new _
    Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Udp);

Yes UDP is supported.
DHCP is not supported yet.

This is a simple UDP send(client) example:


using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Net;
using GHIElectronics.NETMF.Net.Sockets;
using GHIElectronics.NETMF.Net.NetworkInformation;
using System.Text;
using Socket = GHIElectronics.NETMF.Net.Sockets.Socket;

namespace FEZ_Panda_UDP
{
    public class Program
    {
        public static void Main()
        {
            byte[] ip = { 192, 168, 0, 200 };
            byte[] subnet = { 255, 255, 255, 0 };
            byte[] gateway = { 192, 168, 0, 1 };
            byte[] mac = { 43, 185, 44, 2, 206, 127 };
            WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, (Cpu.Pin)FEZ_Pin.Digital.Di9); // WIZnet interface on FEZ Panda
            NetworkInterface.EnableStaticIP(ip, subnet, gateway, mac);
            NetworkInterface.EnableStaticDns(new byte[] { 192, 168, 0, 1 });

            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            IPAddress DestinationIP = new IPAddress(new byte[] { 192, 168, 0, 1 });
            IPEndPoint DestinationEndPoint = new IPEndPoint(DestinationIP, 2000);

            byte[] buf;
            for(int y=0; y <1000; y++)
            {
                              
                Thread.Sleep(2000);
                buf = Encoding.UTF8.GetBytes("Hello World from FEZ Panda" + y.ToString());
                try
                {
                    socket.SendTo(buf, DestinationEndPoint);
                }
                catch
                {
                }
            }
        }
    }
}


A simple UDP receive example:

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Net;
using GHIElectronics.NETMF.Net.Sockets;
using GHIElectronics.NETMF.Net.NetworkInformation;
using System.Text;
using Socket = GHIElectronics.NETMF.Net.Sockets.Socket;

namespace FEZ_Panda_UDP
{
    public class Program
    {
        public static void Main()
        {
            byte[] ip = { 192, 168, 0, 200 };
            byte[] subnet = { 255, 255, 255, 0 };
            byte[] gateway = { 192, 168, 0, 1 };
            byte[] mac = { 43, 185, 44, 2, 206, 127 };
            WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, (Cpu.Pin)FEZ_Pin.Digital.Di9); // WIZnet interface on FEZ Panda
            NetworkInterface.EnableStaticIP(ip, subnet, gateway, mac);
            NetworkInterface.EnableStaticDns(new byte[] { 192, 168, 0, 1 });

            Socket serversocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 2000);
            serversocket.Bind(remoteEndPoint);
            int i = 1;

            while (true)
            {
               
                if (serversocket.Poll(-1, SelectMode.SelectRead))
                {
                    byte[] inBuf = new byte[serversocket.Available];
                    int count = serversocket.ReceiveFrom(inBuf, ref remoteEndPoint);
                    Debug.Print(new String(Encoding.UTF8.GetChars(inBuf)));
                    
                }
                
            }
        }
    }
}

    #### Exception System.Exception - 0x00000000 (1) ####
    #### Message: Currently, Connect methoud is only for TCP.
    #### GHIElectronics.NETMF.Net.Sockets.Socket::Connect [IP: 0018] ####
    #### Fez_webserver.MySocketServer::NTPTime [IP: 001d] ####
    #### Fez_webserver.MySocketServer::UpdateNTP [IP: 0008] ####
    #### Fez_webserver.MySocketServer::Main [IP: 0082] ####
A first chance exception of type 'System.Exception' occurred in GHIElectronics.NETMF.W5100.dll

is thrown at s.Connect(ep) statement:


            IPEndPoint ep = new IPEndPoint(Dns.GetHostEntry(TimeServer).AddressList[0], 123);

            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            s.Connect(ep);

That’s perhaps an older example but supposedly a working example from a Cobra, it was taken from Chris’ internet weather project in the time sync section.

I refreshed the beta some days ago when it was released, I’ve reflashed the firmware again now to verify i’ve done it, device capabilities shows:


 ClrInfo.clrVersion:                     4.1.2821.0
ClrInfo.clrVendorInfo:                  Microsoft Copyright (C) Microsoft Corporation.  All rig
ClrInfo.targetFrameworkVersion:         4.1.2821.0
SolutionReleaseInfo.solutionVersion:    4.1.2.1
SolutionReleaseInfo.solutionVendorInfo: GHI Electronics, LLC
SoftwareVersion.BuildDate:              Sep 20 2010
SoftwareVersion.CompilerVersion:        310739

and properties of all my GHI references show 4.1.2.1 in VS. Anyone with thoughts?

(edit: added end point statement)

Look at the examples posted by Gus.

You only use connect to setup a TCP connection which is persistent. The exception told you this.

UDP is connectionless. There is no concept of a session.

I posted the example. Not Gus. ???

Sorry Joe!

I feel so ashamed. :wink:

ok, so here’s the “make it the same” comment. This is from apparently working code (I can’t confirm, I don’t have a Cobra yet). If that’s the way the netmf sockets work, shouldn’t W5100 work the same? Mike, you have a Cobra IIRC, any chance you can test/compare?

You do not need cobra. You can test this on the emulator

Gus,

are you sure about that?

I tried the TCP / Web Server Tutorial code in the emulator, but it bombs out with:

[quote]An unhandled exception of type ‘System.InvalidOperationException’ occurred in FEZCobra_GHIElectronics.NETMF.FEZ.dll

Additional information: FEZ Cobra not detected![/quote]

and clicking Continue gives:

clicking Continue again will stop running the app.

Any idea what I might be doing wrong?

Debugger output:

[quote]Found debugger!

The debugging target runtime is loading the application assemblies and starting execution.
Loading Deployment Assemblies.

Resolving.

The debugging target runtime is loading the application assemblies and starting execution.
Ready.

‘Microsoft.SPOT.Emulator.Sample.SampleEmulator.exe’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.1\Assemblies\le\mscorlib.dll’, Symbols loaded.
‘Microsoft.SPOT.Emulator.Sample.SampleEmulator.exe’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.1\Assemblies\le\Microsoft.SPOT.Native.dll’, Symbols loaded.
‘Microsoft.SPOT.Emulator.Sample.SampleEmulator.exe’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.1\Assemblies\le\Microsoft.SPOT.Hardware.dll’, Symbols loaded.
‘Microsoft.SPOT.Emulator.Sample.SampleEmulator.exe’ (Managed): Loaded ‘C:\Program Files\GHI Electronics\GHI NETMF v4.1 SDK\Assemblies\le\FEZCobra_GHIElectronics.NETMF.FEZ.dll’
‘Microsoft.SPOT.Emulator.Sample.SampleEmulator.exe’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.1\Assemblies\le\Microsoft.SPOT.Net.dll’, Symbols loaded.
‘Microsoft.SPOT.Emulator.Sample.SampleEmulator.exe’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.1\Assemblies\le\System.dll’, Symbols loaded.
‘Microsoft.SPOT.Emulator.Sample.SampleEmulator.exe’ (Managed): Loaded ‘C:\Users\Eric\Documents\Visual Studio 2010\Projects\FEZCobraDomotica\FEZCobraDomotica\bin\Debug\le\FEZ Cobra Console Application.exe’, Symbols loaded.
#### Exception System.InvalidOperationException - 0x00000000 (2) ####
#### Message: FEZ Cobra not detected!
#### GHIElectronics.NETMF.FEZ._Checker::.cctor [IP: 000c] ####
An unhandled exception of type ‘System.InvalidOperationException’ occurred in FEZCobra_GHIElectronics.NETMF.FEZ.dll

Additional information: FEZ Cobra not detected!

Uncaught exception
The thread ‘’ (0x2) has exited with code 0 (0x0).
#### Exception System.Exception - CLR_E_FAIL (1) ####
#### Message:
#### Microsoft.SPOT.Net.NetworkInformation.NetworkInterface::UpdateConfiguration [IP: 0000] ####
#### Microsoft.SPOT.Net.NetworkInformation.NetworkInterface::EnableStaticIP [IP: 0028] ####
#### FEZCobraDomotica.Program::Main [IP: 0035] ####
A first chance exception of type ‘System.Exception’ occurred in Microsoft.SPOT.Net.dll
An unhandled exception of type ‘System.Exception’ occurred in Microsoft.SPOT.Net.dll

Uncaught exception
The thread ‘’ (0x1) has exited with code 0 (0x0).
Done.

The program ‘[4564] Micro Framework application: Managed’ has exited with code 0 (0x0).

[/quote]

So I made a brand new test console app with no GHI references only netmf, left it’s target as the emulator.


        public static void Main()
        {
            IPEndPoint ep = new IPEndPoint(Dns.GetHostEntry("time.windows.com").AddressList[0], 123);

            // Connect to timeserver
            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            s.Connect(ep);
}

Stepped through that without error on the UDP connect. So that says to me, wiz5100 code is doing something “different”.

EriSan, the GHI specifics aren’t in the emulator, so you’ll get that kind of error when trying to run a “true” hardware code on the standard emulator (as an aside, someone here who I can’t remember is making great inroads at extending the emulator to handle this).

What Gus meant (what I assume he meant) was that to test the standard NetMF sockets behavior you could just do that in the emulator… see my post one up…

Yeah, I wasn’t clear.

You can compare the Microsoft sockets on emulator to the GHI sockets on wiznet. They should behave exactly the same way…at least this is the goal :slight_smile:

The method Connect() Receive() Send() work for TCP and UDP in FEZ Cobra ( Microsoft’s sockets). They work only with TCP sockets now with Wiznet sockets. Use ReceiveFrom() and SendTo() for UDP.

And If you asked why, I would say that’s because we wanted to keep the driver as optimized as possible to keep the flash space.

Do you think it is important to add this kind of support? Don’t you think it is kind of redundancy?

ok, so now we’ve confirmed that the functionality is different. That’s at least easier to understand than something doesn’t work.

Whether I think the behaviour should be the same or not really is somewhat irrelevant. Depends on what you think the goal is. My preference is to make code transportable across devices. That means if it works one way on Cobra with pure netmf sockets, the same code should work with the wiz5100 socket implementation.

BUT…

I would prioritise having the wiz5100 code that is implemented work exactly the same as netmf, above having some of the code that is achievable through a different methodology re-implemented just for compatibility.

What I would say is that it is very important in documenting the differences when someone comes to use the w5100 support. The exception that is spat out for me here was clear - you can’t use Connect() when using UDP - but what wasn’t clear was whether that was just because the early iteration of the beta hadn’t yet got around to implementing it (ie feature removed) and certainly didn’t point me to know that there was another way around it (and my novice skills wouldn’t have known how to figure that out on my own either!).

From GHI library documentation

[quote]If you are using a connectionless protocol such as UDP, you should call Connect. You should use SendTo() and ReceiveFrom() instead.[/quote] There is a missing “NOT” in the sentence, This will be fixed. :wink:

who would have thought those three letters would change the meaning so much…

:wink:

I don’t say thanks for everything earlier here - I really REALLY want to thank you Joe and GHI team for the work you guys put in here. It’s awesome, I can’t sing your praises loud enough. THANK YOU !