I got a problem with receiving some UDP communication using a Domino and the W5100 ethernet board. I’ve been using the example at [url]http://www.tinyclr.com/downloads/Shield/Broch_EthernatShield.pdf[/url] as a start.
I’ve changed the code so it worked at my network and ended up with the code below for my Domino. To test the Domino there is a small WinForm application, sending a UDP message. To recreate the WinForm application drag a button on a form and call the SendUdpMessage sub when clicking on the button.
The problems are at the lines with remoteEndPoint. An endpoint with the port != 0 will work. Normally port 0 is used to specify any port, but there is nothing received anymore? What do I miss?
WinForm Application
public void SendUdpMessage()
{
System.Net.Sockets.UdpClient socket = new System.Net.Sockets.UdpClient();
byte[] msg = System.Text.Encoding.UTF8.GetBytes("TestMessage");
IPEndPoint EndPoint = new IPEndPoint(IPAddress.Parse("10.0.64.188"), 2000);
socket.Send(msg, msg.Length, EndPoint);
}
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Net;
using GHIElectronics.NETMF.Net.Sockets;
using GHIElectronics.NETMF.Net.NetworkInformation;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using System;
using System.Text;
Namespace MyNamespace
{
public class Program
{
private static void Main()
{
byte[] ip = { 10, 0, 64, 188 };
byte[] subnet = { 255, 255, 255, 0 };
byte[] gateway = { 10, 0, 64, 254 };
byte[] mac = { 42, 173, 190, 239, 254, 237 };
WIZnet_W5100.Enable(SPI.SPI_module.SPI1,
(Cpu.Pin)FEZ_Pin.Digital.Di10,
(Cpu.Pin)FEZ_Pin.Digital.Di9, true);
NetworkInterface.EnableStaticIP(ip, subnet, gateway, mac);
NetworkInterface.EnableStaticDns(new byte[] { 10, 0, 64, 254 });
Socket serversocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
//EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Parse("10.0.64.72"), 2000); // works
//EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 2000); // works
EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Parse("10.0.64.72"), 0); // fails
//EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0); // fails
serversocket.Bind(remoteEndPoint);
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)));
}
}
}
}
}