Socket Socket { get; set; }
public UdpClient(int port)
{
LocalPort = port;
try
{
Socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
IPEndPoint broadcastEndPoint = new IPEndPoint(System.Net.IPAddress.Any, LocalPort);
Socket.Bind(broadcastEndPoint);
}
catch
{
throw;
}
new Thread(new ThreadStart(threadStartTarget)).Start();
}
public int Send(byte[] data, EndPoint endPoint)
{
return Socket.SendTo(data, endPoint);
}
This works for me and should give you a good starting point.
You might have to use the broadcast IPEndPoint to send broadcast.