Esempio n. 1
0
        private void Connect(int attempts)
        {
            try {
                _client.Connect();
                SpeechHost = _client.ServiceProxy;
                //make sure the interface is supported
                try {
                    var speakHostVersion = SpeechHost.version();
                    if (speakHostVersion != SPEAKER_INTERFACE_VERSION)
                    {
                        Console.WriteLine("Speaker API version mismatch");
                        DisconnectNow();
                        return;
                    }
                }
                catch (Exception exception) {
                    Console.WriteLine($"Error attempting to connect to server, please check your connection options: {exception.Message}");
                    DisconnectNow();
                    return;
                }

                var response = SpeechHost.Connect(HostName, ClientName, IpAddress, _username, _password);

                if (string.IsNullOrEmpty(response))
                {
                    return;
                }

                Console.WriteLine($"Error, Unable to connect speaker client interface: {response}");
                DisconnectNow();
            }
            catch (Exception exception) {
                Console.WriteLine($"Cannot connect speaker client attempt {attempts.ToString()}");
                if (exception.Message.ToLower().Contains("timeout occurred.") && attempts < 6)
                {
                    Connect(attempts + 1);
                }
                else
                {
                    DisconnectNow();
                    Console.WriteLine($"Error, Unable to connect speaker client interface: {exception.Message}");
                }
            }
        }
Esempio n. 2
0
        public bool Connect(string username, string password)
        {
            lock (objlock)
            {
                string ipAddress = "127.0.0.1";

                Logger.LogInfo("Connecting speaker client {0} to HomeSeer IP {1}", _clientName, ipAddress);

                try
                {
                    _client = ScsServiceClientBuilder.CreateClient <ISpeechAPI>(new ScsTcpEndPoint(ipAddress, 10401), this);
                    _client.Disconnected += new EventHandler(ClientDisconnected);
                    _client.Connected    += new EventHandler(ClientConnected);
                }
                catch (Exception e)
                {
                    Logger.LogError(e.ToString());
                    return(false);
                }

                try
                {
                    _client.Connect();
                    _speakHost = _client.ServiceProxy;
                    //make sure the interface is supported
                    int v;
                    try
                    {
                        v = _speakHost.version();
                    }
                    catch (Exception e)
                    {
                        Logger.LogError("Error attempting to connect to server, please check your connection options: {0}", e.Message);
                        return(false);
                    }

                    if (v != SPEAKER_INTERFACE_VERSION)
                    {
                        Logger.LogError("Speaker API version mismatch");
                        return(false);
                    }

                    //string localIp = Util.GetLocalIp();
                    string rval = _speakHost.Connect("Sample Plugin", _clientName, "127.0.0.1", username, password);

                    if (!string.IsNullOrEmpty(rval))
                    {
                        Logger.LogError("Error, Unable to connect speaker client interface: {0}", rval);
                        DisconnectNow();
                        return(false);
                    }
                }
                catch (Exception e)
                {
                    Logger.LogError("Error while connecting speaker client: {0}", e.ToString());
                    return(false);
                }
            }

            return(true);
        }