Example #1
0
 public TcpServerOrb(ArgParser args, BuildOrbDevice orb)
 {
     _orb       = orb;
     _converter = new ColorByteConverter();
     if (args.ServerIpAddressDetected)
     {
         ServerIpAddress = IPAddress.Parse(args.ServerAddress);
     }
     else
     {
         var ips = Dns.GetHostAddresses(args.ServerAddress);
         if (ips == null || ips.Length == 0)
         {
             args.ThrowIncorrectServerAddress(args.ServerAddress);
         }
         if (ips.Any(x => x.AddressFamily.ToString() == ProtocolFamily.InterNetwork.ToString()))
         {
             ServerIpAddress = ips.First(x => x.AddressFamily.ToString() == ProtocolFamily.InterNetwork.ToString());
         }
         else
         {
             ServerIpAddress = ips.Last();
         }
     }
     _listener = new TcpListener(ServerIpAddress, args.PortNumber);
     if (args.CountProgressColors)
     {
         _colorCounter = new ProgressColorCounter(args.ProgressColorForServer, args.SuccessColorForServer);
     }
     else
     {
         _colorCounter = new NullColorCounter();
     }
 }
Example #2
0
        public void TurnLightningOn(OrbColor color)
        {
            //Зажигаем
            var  converner = new ColorByteConverter();
            byte colorByte = converner.Color2Byte(color);

            TurnLightningOn(colorByte);
        }
Example #3
0
        public TcpClientOrb(ArgParser args, ColorByteConverter converter)
        {
            _converter = converter;
            _client    = new TcpClient();
            var result  = _client.BeginConnect(args.ServerAddress, args.PortNumber, null, null);
            var success = result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(2));

            if (!success)
            {
                throw new ApplicationException(string.Format("Failed to connect to host {0} port {1}.", args.ServerAddress, args.PortNumber));
            }

            // we have connected
            _client.EndConnect(result);
        }