Пример #1
0
        public void Start()
        {
            try
            {
                var udpHandler = new UdpHandler();
                udpHandler.StartUdpMulticastListenerAsync(this);
                listener = new TcpListener(IPAddress.Parse(Address), Port);
                listener.Start();

                while (true)
                {
                    TcpClient client    = listener.AcceptTcpClient();
                    Client    clientObj = new Client(client, this);

                    // создаем новый поток для обслуживания нового клиента
                    Thread clientThread = new Thread(new ThreadStart(clientObj.Process));
                    clientThread.Start();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                listener?.Stop();
            }
        }
Пример #2
0
        public void StartUdpMulticastListenerAsync(Node node)
        {
            Task.Run(() =>
            {
                try
                {
                    var nmo          = new UdpHandler();
                    nmo.mcastAddress = IPAddress.Parse("224.168.100.2");
                    nmo.mcastPort    = 12000;

                    // Start a multicast group.
                    nmo.StartMulticast();
                    nmo.MulticastOptionProperties();
                    // Receive broadcast messages.
                    nmo.ReceiveBroadcastMessages(node);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            });
        }