/// <summary> /// Stops working of TCP client /// </summary> public static void StopServerClient() { if (serverClientInstance == null) { return; } try { serverClientInstance.client.GetStream().Close(); serverClientInstance.client.Close(); } catch (Exception exception) { serverClientInstance.logger.UpdateLog($"TCP client stopping exception: {exception.Message}"); } serverClientInstance.isConnected = false; serverClientInstance = null; }
/// <summary> /// Starts TCP client /// </summary> public static TcpServerClient RunServerClient(ConnectionData connData, ITcpLogger logger) { if (connData == null) { throw new Exception("connection data is NULL!"); } if (logger == null) { throw new Exception("logger is NULL!"); } if (serverClientInstance != null) { throw new Exception("a working TCP client detected!"); } serverClientInstance = new TcpServerClient(connData, logger); serverClientInstance.StartServerClient(); return(serverClientInstance); }