예제 #1
0
 internal bool Connect()
 {
     try
     {
         bIsFirst = true;
         logger.Info("Trying to connect....");
         IPAddress addr = IPAddress.Loopback;
         if (!IPAddress.TryParse(Program.Config.ServerHost, out addr))
         {
             IPAddress[] addresses = Dns.GetHostAddresses(Program.Config.ServerHost);
             if (addresses.Length == 0)
             {
                 throw new InvalidOperationException("Host not found");
             }
             addr = addresses[0];
         }
         serverConnection = new EventDrivenTCPClient(addr, Program.Config.ServerTelnetPort, true);
         serverConnection.DataReceived            += serverConnection_DataReceived;
         serverConnection.ConnectionStatusChanged += serverConnection_ConnectionStatusChanged;
         serverConnection.Connect();
         if (_Testing)
         {
             CommandsDisabled = true;
         }
     }
     catch (Exception ex)
     {
         logger.Warn("Connection failed");
         logger.Warn(ex.ToString());
         return(false);
     }
     return(serverConnection.IsConnected);
 }
예제 #2
0
        public void StartTempUpdate(double secondsBetweenUpdates)
        {
            m_updateTimer = new Timer(updateTemperatureCallback, null, TimeSpan.FromSeconds(secondsBetweenUpdates), TimeSpan.FromSeconds(secondsBetweenUpdates));

            if (!IsConnected())
            {
                m_simpleClient.Connect();
            }
        }
예제 #3
0
 public override void Start()
 {
     if (running)
     {
         return;
     }
     Enabled = true;
     client  = new EventDrivenTCPClient(Host, Port, true);
     client.Connect();
     client.DataReceived += Client_DataReceived;
     running              = true;
 }