UDP with Ethershield

Thanks a lot
Works very well
Seem i still have a long way to go in C#

Regards :stuck_out_tongue:

Please, edit your post, select all the code and click on the code button (the image with 101010)

Eric

This is a working UDP 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,true); // 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)));
 
                }
 
            }
        }
    }
}

Hi al, i’ve been very happy with the UDP receive sample, as it works all right. Now, i’m trying to Ssend UDP frames, the sample code in the Ethershield notice seems to work all right, but as far as i can see with a sniffer, nothing is sent .
I’m using an Ethershield on a Domino.

Any ideas

Thanks.

Claude :’(

And where is the code? :wink:

good point.

[url]http://www.tinyclr.com/downloads/Shield/Broch_EthernatShield.pdf[/url]


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,true); // 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
{
}
}
}
}
}

This is weired.
Are you sure that no firewall is set so the sniffer is not getting the packets?
Can you set a simple UDP receiver on your PC to receive the packets? You can use the same code you used for receiving on FEZ since it is .NET socket compatible.

Is the sniffer on the destination machine of the udp send?

If the sniffer is on a third machine, and connected to an ethernet switch, it most likely will not be able to see the packets.

Are the packets not arriving at the destination?

Yes, the sniffer is on the destination machine.
i even tried to send to the broadcast adress : 192.168.0 255 and 255.255.255.255
I see nothing coming from Ip 192.168.0.200 or Port 2000.

Update

I finally got it. The problem : my “Intelligent” (managed) switch was unable to understand the ARP requests when the connection started.
I was able to make it work on a ‘dumb’ switch.

It appears that the two lower bits in the first octet of the mac address have a special meaning. Change 43 to 40 so these bits are set to 0 and it works like a charm !

Claude