Hi all,
A quick query - I can’t get an extremely simple UDP server to work on the ChipworkX Development system. I’m running the latest firmware 4.1.5.1 (Reflashed both tinybooter and tinyclr to ensure they are correct). The socket.Bind fails resulting in the Socket.Poll throwing an exception ErrorCode 10057. The thing is this is based on the example from Jens Kuhner’s book Expert .Net Micro Framework (2nd Edition).
Am I missing something with regards to the hardware set-up or am I misusing sockets in some way?
Thanks in advance for any help.
Michael.
using System;
using Microsoft.SPOT;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace ChipworkXEthernetUDP
{
public class Program
{
private const int port = 2000;
public static void Main()
{
using (Socket serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp))
{
EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, port);
serverSocket.Bind(remoteEndPoint);
if (serverSocket.Poll(-1, SelectMode.SelectRead))
{
byte[] inBuffer = new byte[serverSocket.Available];
int count = serverSocket.ReceiveFrom(inBuffer, ref remoteEndPoint);
string message = new string(Encoding.UTF8.GetChars(inBuffer));
Debug.Print("Received '" + message + "'.");
}
}
}
}
}