private static void StopClient() { if (_client == null) return; _client.Dispose(); _client = null; _registered = false; }
internal static void StopClient() { if (_client != null) { _client.Dispose(); _client = null; } }
private static bool StartClient(IPEndPoint endPoint) { if (_client != null) return false; ClientMessageSink sink = ReceivedMessage; _client = new Client(endPoint, sink); _client.CommsFailureCallback = CommsFailure; _client.ConnectCallback = Connected; _client.DisconnectCallback = Disconnected; if (_client.Start()) { return true; } else { _client = null; return false; } }
/// <summary> /// Connects the IR client to the host specified by the parameter <paramref name="endPoint"/>. /// </summary> /// <returns><c>true</c>, if the client could successfully be started, else <c>false</c>.</returns> public bool StartClient(IPEndPoint endPoint) { ServiceRegistration.Get<ILogger>().Info("IrInputPlugin: Connect to service ({0}:{1})", endPoint.Address, endPoint.Port); if (_client != null) return false; ClientMessageSink sink = ReceivedMessage; _client = new Client(endPoint, sink) { CommsFailureCallback = CommsFailure, ConnectCallback = Connected, DisconnectCallback = Disconnected }; if (_client.Start()) return true; _client = null; return false; }
/// <summary> /// Stops the IR client. /// </summary> public void StopClient() { if (_client == null) return; _client.Dispose(); _client = null; }
internal static bool StartClient(IPEndPoint endPoint) { if (_client != null) return false; _notifyIcon.Icon = Resources.Icon16Connecting; _notifyIcon.Text = "Translator - Connecting ..."; ClientMessageSink sink = ReceivedMessage; _client = new Client(endPoint, sink); _client.CommsFailureCallback = CommsFailure; _client.ConnectCallback = Connected; _client.DisconnectCallback = Disconnected; if (_client.Start()) return true; _client = null; return false; }
internal static bool StartClient(IPEndPoint endPoint) { if (_client != null) return false; ClientMessageSink sink = new ClientMessageSink(ReceivedMessage); _client = new Client(endPoint, sink); _client.CommsFailureCallback = new WaitCallback(CommsFailure); _client.ConnectCallback = new WaitCallback(Connected); _client.DisconnectCallback = new WaitCallback(Disconnected); if (_client.Start()) { return true; } else { _client = null; return false; } }
/// <summary> /// Connect the IRSS client to any IRSS server. /// </summary> /// <returns>true if the disconnection is successful</returns> public bool Disconnect() { try { if (!Connected || irss == null) { LogWarn("Not connected"); return true; } LogInfo("Disconnect " + ServerHost); IrssMessage message = new IrssMessage(MessageType.UnregisterClient, MessageFlags.Request); irss.Send(message); Connected = false; ServerHost = ""; irss.Dispose(); irss = null; } catch (Exception ex) { LogErr(ex.Message); return false; } return true; }
//------------------------------------------------------------------------------------------------------------------ #region methods /// <summary> /// Connect the IRSS client to an IRSS server. /// </summary> /// <param name="host">Computer running the IRSS server to which the client should connect</param> /// <param name="millisecondsTimeout">Wait for the connection to succeed for that many milliseconds</param> /// <returns>true if the connection is successful</returns> public bool Connect(string host = "", int millisecondsTimeout = 10000) { // If connected, first disconnect if (Connected) { if (ServerHost == host) { LogWarn("Already connected to " + ServerHost); return true; } else { Disconnect(); } } // reset connection states Connected = false; if (host == "") host = ServerHost; if (host == "") host = "localhost"; IPAddress serverIP = Network.GetIPFromName(host); IPEndPoint endPoint = new IPEndPoint(serverIP, Server.DefaultPort); ClientMessageSink sink = ReceivedMessage; irss = new Client(endPoint, sink); if (irss == null) { LogErr("Failed to open connection to " + host); return false; } irss.CommsFailureCallback = CommsFailure; irss.ConnectCallback = SocketConnected; irss.DisconnectCallback = SocketDisconnected; bool ok = irss.Start(); if (ok) { ServerHost = host; // Wait for the connection to occur. if (!_connectedEvent.WaitOne(millisecondsTimeout)) { LogErr("Failed to connect to " + ServerHost); return false; } LogInfo("Client connected to " + host); Connected = true; } return ok; }
private void StartClient(IPEndPoint endPoint) { if (_client != null) return; _client = new Client(endPoint, ReceivedMessage); _client.CommsFailureCallback = CommsFailure; _client.ConnectCallback = Connected; _client.DisconnectCallback = Disconnected; if (_client.Start()) { return; } _client = null; }