예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TTLSServerSocket" /> class.
        /// </summary>
        /// <param name="port">The port where the server runs.</param>
        /// <param name="clientTimeout">Send/receive timeout.</param>
        /// <param name="useBufferedSockets">If set to <c>true</c> [use buffered sockets].</param>
        /// <param name="certificate">The certificate object.</param>
        /// <param name="clientCertValidator">The certificate validator.</param>
        /// <param name="localCertificateSelectionCallback">The callback to select which certificate to use.</param>
        /// <param name="sslProtocols">The SslProtocols value that represents the protocol used for authentication.</param>
        public TTLSServerSocket(
            Int32 port,
            Int32 clientTimeout,
            Boolean useBufferedSockets,
            X509Certificate2 certificate,
            RemoteCertificateValidationCallback clientCertValidator             = null,
            LocalCertificateSelectionCallback localCertificateSelectionCallback = null,
            // TODO: Enable Tls11 and Tls12 (TLS 1.1 and 1.2) by default once we start using .NET 4.5+.
            SslProtocols sslProtocols = SslProtocols.Tls)
        {
            if (!certificate.HasPrivateKey)
            {
                throw new TTransportException(TTransportException.ExceptionType.Unknown, "Your server-certificate needs to have a private key");
            }

            this.port                = port;
            this.clientTimeout       = clientTimeout;
            serverCertificate        = certificate;
            this.useBufferedSockets  = useBufferedSockets;
            this.clientCertValidator = clientCertValidator;
            this.localCertificateSelectionCallback = localCertificateSelectionCallback;
            this.sslProtocols = sslProtocols;
            try
            {
                // Create server socket
                server = TSocketVersionizer.CreateTcpListener(this.port);
                server.Server.NoDelay = true;
            }
            catch (Exception ex)
            {
                server = null;
                throw new TTransportException("Could not create ServerSocket on port " + this.port + ".", ex);
            }
        }
예제 #2
0
 public TServerSocket(Int32 port, Int32 clientTimeout, Boolean useBufferedSockets)
 {
     this.port               = port;
     this.clientTimeout      = clientTimeout;
     this.useBufferedSockets = useBufferedSockets;
     try
     {
         // Make server socket
         server = TSocketVersionizer.CreateTcpListener(this.port);
         server.Server.NoDelay = true;
     }
     catch (Exception ex)
     {
         server = null;
         throw new TTransportException("Could not create ServerSocket on port " + this.port + ".", ex);
     }
 }
예제 #3
0
 private void InitSocket()
 {
     TcpClient = TSocketVersionizer.CreateTcpClient();
     TcpClient.ReceiveTimeout = TcpClient.SendTimeout = timeout;
     TcpClient.Client.NoDelay = true;
 }