Пример #1
0
        void Connect(ref ComClient client)
        {
            bool      connected = false;
            Stopwatch sw        = new Stopwatch();

            client.SetBeaconAcceptFunction((data) => { if (data == "Test")
                                                       {
                                                           return(true);
                                                       }
                                                       else
                                                       {
                                                           return(false);
                                                       } });

            client.OnConnected += (node) =>
            {
                connected = true;
            };
            client.Open();
            client.AcceptBeacon = true;

            //server.Server.BeaconStart();
            //server.Server.SendConnectBeacon("127.0.0.1");

            client.Connect("127.0.0.1");

            sw.Start();
            while (true)
            {
                if (client.IsConnected && connected)
                {
                    break;
                }
                else if (sw.Elapsed.Seconds >= 3)
                {
                    client.Close();
                    server.Server.BeaconStop();
                    throw new TimeoutException();
                }
                Task.Delay(100);
            }
            sw.Stop();
        }