private void DisconnectNow() { lock (objlock) { try { if (_client != null) { try { if (_speakHost != null) { _speakHost = null; } _client.Disconnect(); _client.Dispose(); } catch (Exception) { } } } catch (Exception) { } } }
public bool Connect(string IP, int Port) { clientService = ScsServiceClientBuilder.CreateClient <ITaxiService>(new ScsTcpEndPoint(IP, Port)); try { clientService.Connect(); } catch { clientService.Dispose(); return(false); } return(true); }
private void DisconnectNow() { if (_client == null) { return; } try { SpeechHost = null; _client.Disconnect(); _client.Disconnected -= OnClientDisconnect; _client.Connected -= OnClientConnect; _client.Dispose(); } catch (Exception exception) { Console.WriteLine($"Error while disconnecting speaker client : {exception.Message}"); } }
private void OnMainFormClosing(Object sender , FormClosingEventArgs e) { Timer.Stop(); if (m_ChangeNotificationObject != null) { TransactionObject transactionObject = m_RemoteAccessClient.ServiceProxy.BeginTransaction(); m_RemoteAccessClient.ServiceProxy.UnregisterForProfileChanges(transactionObject, m_ChangeNotificationObject, true); m_ChangeNotificationObject = null; } if (m_RemoteAccessClient != null) { m_RemoteAccessClient.Disconnect(); m_RemoteAccessClient.Dispose(); m_RemoteAccessClient = null; } }
public static void Main(string[] args) { string serverIp = "127.0.0.1"; string serverCmd = null; foreach (string serverCmd_loopVariable in args) { serverCmd = serverCmd_loopVariable; string[] ch = new string[1]; ch[0] = "="; string[] parts = serverCmd.Split(ch, StringSplitOptions.None); switch (parts[0].ToLower()) { case "server": serverIp = parts[1]; break; case "instance": try { Util.Instance = parts[1]; } catch (Exception) { Util.Instance = ""; } break; } } Console.WriteLine("Plugin: " + Util.IFACE_NAME + " Instance: " + Util.Instance + " starting..."); Console.WriteLine("Connecting to server at " + serverIp + "..."); client = ScsServiceClientBuilder.CreateClient <IHSApplication>(new ScsTcpEndPoint(serverIp, 10400), plugin); clientCallback = ScsServiceClientBuilder.CreateClient <IAppCallbackAPI>(new ScsTcpEndPoint(serverIp, 10400), plugin); int Attempts = 1; TryAgain: try { client.Connect(); clientCallback.Connect(); double APIVersion = 0; try { host = client.ServiceProxy; APIVersion = host.APIVersion; // will cause an error if not really connected Console.WriteLine("Host API Version: " + APIVersion.ToString()); } catch (Exception ex) { Console.WriteLine("Error getting API version from host object: " + ex.Message + "->" + ex.StackTrace); //Return } try { callback = clientCallback.ServiceProxy; APIVersion = callback.APIVersion; // will cause an error if not really connected } catch (Exception ex) { Console.WriteLine("Error getting API version from callback object: " + ex.Message + "->" + ex.StackTrace); return; } } catch (Exception ex) { Console.WriteLine("Cannot connect attempt " + Attempts.ToString() + ": " + ex.Message); if (ex.Message.ToLower().Contains("timeout occurred.")) { Attempts += 1; if (Attempts < 6) { goto TryAgain; } } if (client != null) { client.Dispose(); client = null; } if (clientCallback != null) { clientCallback.Dispose(); clientCallback = null; } wait(4); return; } try { // create the user object that is the real plugin, accessed from the pluginAPI wrapper Util.callback = callback; Util.hs = host; plugin.OurInstanceFriendlyName = Util.Instance; // connect to HS so it can register a callback to us host.Connect(Util.IFACE_NAME, Util.Instance); Console.WriteLine("Connected, waiting to be initialized..."); do { System.Threading.Thread.Sleep(10); } while (client.CommunicationState == HSCF.Communication.Scs.Communication.CommunicationStates.Connected & !HSPI.bShutDown); Console.WriteLine("Connection lost, exiting"); // disconnect from server for good here client.Disconnect(); clientCallback.Disconnect(); wait(2); System.Environment.Exit(0); } catch (Exception ex) { Console.WriteLine("Cannot connect(2): " + ex.Message); wait(2); System.Environment.Exit(0); return; } }
public static void Main(string[] args) { string serverIp = "127.0.0.1"; string serverCmd = null; foreach (string serverCmd_loopVariable in args) { serverCmd = serverCmd_loopVariable; string[] ch = new string[1]; ch[0] = "="; string[] parts = serverCmd.Split(ch, StringSplitOptions.None); switch (parts[0].ToLower()) { case "server": serverIp = parts[1]; break; case "instance": try { Util.Instance = parts[1]; } catch (Exception) { Util.Instance = ""; } break; } } Reconnect: Console.WriteLine("Plugin: " + Util.IFACE_NAME + " Instance: " + Util.Instance + " starting..."); Console.WriteLine("Connecting to server at " + serverIp + "..."); client = ScsServiceClientBuilder.CreateClient <IHSApplication>(new ScsTcpEndPoint(serverIp, 10400), plugin); clientCallback = ScsServiceClientBuilder.CreateClient <IAppCallbackAPI>(new ScsTcpEndPoint(serverIp, 10400), plugin); int Attempts = 1; TryAgain: try { client.Connect(); clientCallback.Connect(); double APIVersion = 0; try { host = client.ServiceProxy; APIVersion = host.APIVersion; // will cause an error if not really connected Console.WriteLine("Host API Version: " + APIVersion.ToString()); } catch (Exception ex) { Console.WriteLine("Error getting API version from host object: " + ex.Message + "->" + ex.StackTrace); //Return } try { callback = clientCallback.ServiceProxy; APIVersion = callback.APIVersion; // will cause an error if not really connected } catch (Exception ex) { Console.WriteLine("Error getting API version from callback object: " + ex.Message + "->" + ex.StackTrace); return; } } catch (Exception ex) { Console.WriteLine("Cannot connect attempt " + Attempts.ToString() + ": " + ex.Message); if (ex.Message.ToLower().Contains("timeout occurred.")) { Attempts += 1; if (Attempts < 6) { goto TryAgain; } } if (client != null) { client.Dispose(); client = null; } if (clientCallback != null) { clientCallback.Dispose(); clientCallback = null; } wait(4); return; } try { connectionJunction(); if (reset) { HSPI.armReset(); goto Reconnect; } else { System.Environment.Exit(0); } } catch (Exception ex) { Console.WriteLine("Cannot connect(2): " + ex.Message); wait(2); System.Environment.Exit(0); return; } }
public void Dispose() { _client.Dispose(); }