Beispiel #1
0
        public void UdpBroadcastRequest()
        {
            MessageSearchRequest message          = new MessageSearchRequest();
            IPAddress            currentIPAddress = NetworkInfo.GetCurrentIP();

            message.Port     = ((IPEndPoint)socketUdpHandler.LocalEndPoint).Port;
            message.IPAdress = currentIPAddress.ToString();
            IPAddress  mask            = NetworkInfo.GetIPv4Mask(currentIPAddress);
            IPAddress  strongBroadcast = NetworkInfo.GetBroadcastAddress(currentIPAddress, mask);
            IPEndPoint IPendPoint      = new IPEndPoint(strongBroadcast, ServerPort);
            Socket     sendRequest     = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            sendRequest.SendTo(messageSerializer.Serialize(message, message.GetType()), IPendPoint);
            Thread threadReceiveUdp = new Thread(ReceiveMessagesUdp);

            threadReceiveUdp.IsBackground = true;
            threadReceiveUdp.Start();
        }