Exemple #1
0
        public void SetClientSocketForUDPListening()
        {
            listeningUDPSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            IPAddress  IPaddress    = CommonInfo.GetHostsIPAddress();
            IPEndPoint IPLocalPoint = new IPEndPoint(IPaddress, SERVERUDPPORT);

            listeningUDPSocket.Bind(IPLocalPoint);

            var message = new Message(IPaddress.ToString(), SERVERUDPPORT, Message.MessageType[6]);

            IPAddress  broadcastIPaddress = CommonInfo.GetHostsBroadcastIPAddress();
            IPEndPoint IPendPoint         = new IPEndPoint(broadcastIPaddress, SERVERUDPPORT);

            listeningUDPSocket.SendTo(messageSerializer.Serialize(message), IPendPoint);

            Thread threadReceiveUDPMessages = new Thread(ReceiveUDPMessages);

            threadsList.Add(threadReceiveUDPMessages);
            threadReceiveUDPMessages.Start();
        }