Example #1
0
        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;
              }
        }
 /// <summary>
 /// Returns the stream used to send and receive data.
 /// </summary>
 /// <returns>The underlying <see cref="SecureNetworkStream"/>.</returns>
 /// <exception cref="ObjectDisposedException">The <see cref="SecureTcpClient"/> has been closed.</exception>
 /// <exception cref="InvalidOperationException">The SecureTcpClient is not connected to a remote host.</exception>
 public virtual SecureNetworkStream GetStream()
 {
     if (CleanedUp)
     {
         throw new ObjectDisposedException(this.GetType().FullName);
     }
     if (!Client.Connected)
     {
         throw new InvalidOperationException();
     }
     if (DataStream == null)
     {
         DataStream = new SecureNetworkStream(Client, false);
     }
     return(DataStream);
 }
 /// <summary>
 /// Releases the unmanaged resources used by the <see cref="SecureTcpClient"/> and optionally releases the managed resources.
 /// </summary>
 protected virtual void Dispose()
 {
     if (!CleanedUp) {
         CleanedUp = true;
         Active = false;
         if (DataStream != null) {
             DataStream.Close();
             DataStream = null;
         }
         if (Client.Connected) {
             try {
                 Client.Shutdown(SocketShutdown.Both);
             } catch {}
         }
         Client.Close();
     }
 }
 /// <summary>
 /// Returns the stream used to send and receive data.
 /// </summary>
 /// <returns>The underlying <see cref="SecureNetworkStream"/>.</returns>
 /// <exception cref="ObjectDisposedException">The <see cref="SecureTcpClient"/> has been closed.</exception>
 /// <exception cref="InvalidOperationException">The SecureTcpClient is not connected to a remote host.</exception>
 public virtual SecureNetworkStream GetStream()
 {
     if (CleanedUp)
         throw new ObjectDisposedException(this.GetType().FullName);
     if (!Client.Connected)
         throw new InvalidOperationException();
     if (DataStream == null) {
         DataStream = new SecureNetworkStream(Client, false);
     }
     return DataStream;
 }
Example #5
0
        public void Dispose()
        {
            try {
            OnDispose();
              } catch (Exception) { }

              Disconnect();

              IsDisposed = true;
              _Stream = null;
              _Reader = null;
              _Connection = null;
        }
Example #6
0
 /// <summary> 
 /// Create a new SecureTcpClient based on an existing one.
 /// </summary>
 /// <param name="client">The SecureTcpClient to copy from.</param>
 public SecureTcpClient(SecureTcpClient client)
     : base()
 {
     m_Client = client.Client;
     m_Active = client.Active;
     m_CleanedUp = client.CleanedUp;
     m_DataStream = client.DataStream;
 }
Example #7
0
 /// <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;
 }