public Server_Advertisement_Message() { IPAddress localIP = LocalNetworkConnection.GetLocalIp(); string ip = localIP.ToString(); _header = SERVER_ADV; _payload = ip + "\r\n"; }
public static void Broadcast(Server_Message message, CancellationToken token) { IPEndPoint rEndPoint = new IPEndPoint(LocalNetworkConnection.GetBroadcastAddress(), ESP_PORT); IPEndPoint lEndPoint = new IPEndPoint(LocalNetworkConnection.GetLocalIp(), ESP_PORT); try { while (token.IsCancellationRequested is false) { client = new UdpClient(lEndPoint); client.EnableBroadcast = true; client.Connect(rEndPoint); Send(message.ToBytes()); client.Close(); Thread.Sleep(6000); } } catch { MessageBox err = new MessageBox("Error creating the socket;\n" + ESP_PORT + " port is already in use.", "Socket exception", icon: System.Windows.MessageBoxImage.Error); err.Show(); return; } }