Exemplo n.º 1
0
        public static void ReciveBroadcastOffer(object available)
        {
            UdpClient  listener = new UdpClient(localPort);                 // для прослушивания сообщений udp приходящих на локальный порт
            IPEndPoint groupEP  = new IPEndPoint(IPAddress.Any, localPort); // адрес приема, для приема всех сообщений

            try
            {
                while (true)
                {
                    // Console.WriteLine("Waiting for broadcast");
                    byte[] bytes = listener.Receive(ref groupEP); // получаем сообщение

                    if (IsLocalAddress(groupEP.Address.ToString()))
                    {
                        continue;
                    }
                    var name = Encoding.ASCII.GetString(bytes, 0, bytes.Length);
                    AvailableConection availableConection = (AvailableConection)available;
                    availableConection.AddMember(groupEP.Address, name);
                }
            }
            catch (SocketException e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                listener.Close();
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Thread getConnectThread = new Thread(new ThreadStart(ConnectionV2.GetConnect));

            getConnectThread.Start();
            //ConnectionV2.GetConnect();
            while (true)
            {
                if (!AvailableConection.IfWasEdited)
                {
                    continue;
                }
                Console.WriteLine();
                var ls = AvailableConection.ReturnGroupList();
                foreach (var mem in ls)
                {
                    Console.WriteLine("connection from - " + mem);
                }
            }
        }