public void Connect(string hostname, int port, bool ssl) { try { Host = hostname; Port = port; Ssl = ssl; var protocol = ssl ? SecureProtocol.Tls1 | SecureProtocol.Ssl3 : SecureProtocol.None; SecurityOptions options = new SecurityOptions(protocol); options.Certificate = null; options.Entity = ConnectionEnd.Client; options.CommonName = hostname; options.VerificationType = CredentialVerification.Auto; options.Flags = SecurityFlags.Default; options.AllowedAlgorithms = SslAlgorithms.SECURE_CIPHERS; //_Connection = new TcpClient(hostname, port); _Connection = new SecureTcpClient(hostname, port, options); _Stream = _Connection.GetStream(); _Reader = new StreamReader(_Stream, System.Text.Encoding.Default); string info = _Reader.ReadLine(); OnConnected(info); IsConnected = true; Host = hostname; } catch (Exception) { IsConnected = false; throw; } }
public void Dispose() { try { OnDispose(); } catch (Exception) { } Disconnect(); IsDisposed = true; _Stream = null; _Reader = null; _Connection = null; }
/// <summary><see cref="Ch.Elca.Iiop.ITranport.CloseConnection/></summary> public void CloseConnection() { try { if (m_socket != null) { m_socket.Close(); } } catch { // ignore } m_socket = null; try { if (m_stream != null) { m_stream.Close(); // close the stream and the socket. } } catch { // ignore } m_stream = null; }