Main Site Documentation

Socket.SendTo is blocking on UDP for Domino on NetMf 4.1


#1

Hi,

I’ve got the following test code on my device and when I attempt to broadcast a UDP packet on the network, it blocks at the SendTo line. I have references to FezDomino_GhiElectronics.NetMF.Fez, GHIElectronics.NETMF.Net and GHIElectronics.NETMF.W5100 and I’m using the pin compatible Arduino Ethernet shield.

Had all this running before but can’t figure out what changed;


using System;
using System.Threading;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Net;
using GHIElectronics.NETMF.Net.Sockets;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

namespace FEZ_Domino_Application1
{
    public class Program
    {
        public static void Main()
        {
            bool ledState = false;

            OutputPort led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, ledState);

            while (true)
            {
                Thread.Sleep(500);

                ledState = !ledState;
                led.Write(ledState);

                Debug.Print(DateTime.Now.ToString());
                byte[] messageBytes = { 20, 30, 40, 0 };
                using (Socket clientSocket = new Socket(AddressFamily.InterNetwork,SocketType.Dgram,ProtocolType.Udp))
                {
                    // Addressing
                    IPHostEntry entry = Dns.GetHostEntry("255.255.255.255"); // UDP broadcast address for local network.
                    IPAddress ipAddress = entry.AddressList[0];
                    IPEndPoint serverEndPoint = new IPEndPoint(ipAddress, 2000);

                    Debug.Print("sock");

                    // Blocks here, UDP is connectionless so I'm guessing I have a wrong library?
                    clientSocket.SendTo(messageBytes, serverEndPoint);
                    Debug.Print("sockend");
                }
            }
        }
    }
}


This is a brand new project, so no old duff references in there (hopefully).


#2

I don’t see the Initialisation code or the networking settings such as setting the local IP address or the DNS server.

Please take a look at this this document
http://www.ghielectronics.com/downloads/FEZ/Shield/Broch_EthernatShield.pdf


#3

Hello :slight_smile:

Once you would have properly initialized your WIZ5100 IP stack, try to replace to whole weird addressing stuff by the following code. Why trying to look up DNS of a string that is already an IP address ???


IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse("255.255.255.255"), 2000);

Also there is a nice example here:
http://code.tinyclr.com/project/284/udp-transceive-data-with-fez-connect/


#4

Ah, dumb mistake!

My head had it as ‘I don’t need an IP address because I’m broadcasting on UDP’ but obviously I need to initialise.

Thanks chaps.


#5

Something I just found out that you guys might like to change or annotate in your samples.

The MAC address you use in the demo is not correctly formed (at a guess) as I’ve been going round in circles for two days now trying to get a Domino to broadcast only to find that the MAC address I’ve been using has meant that the router filters it out.

It works fine point to point with a swapover cable, but plugging into a router means that it won’t get recognised as a valid network device.

I copied an existing MAC address from an old system and it runs nice now.