public void Send(byte[] message, IPEndPoint endPoint = null)
{
lock (SyncRoot)
{
var udpSendClient = new UdpClient() {EnableBroadcast = true};
udpSendClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
try
{
udpSendClient.Client.Bind(new IPEndPoint(Address, UdpPort));
}
catch (Exception ex)
{
_logger.ErrorException("Bind error", ex);
return;
}
if (endPoint == null)
udpSendClient.Connect(Broadcast, UdpPort);
else
udpSendClient.Connect(endPoint.Address, endPoint.Port);
udpSendClient.Send(message, message.Length);
udpSendClient.Close();
/*var s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
var ep = new IPEndPoint(Broadcast, 47808);
s.SendTo(message, ep);
s.Close();*/
}
}