private async Task ClientOpen(TcpTlsConnection client)
        {
            // A client has connected. Create the
            // SslStream using the client's network stream.
            client.SslStream = new SslStream(client.Client.GetStream(), false);
            // Authenticate the server but don't require the client to authenticate.
            try
            {
                await client.SslStream.AuthenticateAsServerAsync(ServerCertificate, false, SslProtocolLevel, true);

                // Set timeouts for the read and write to 5 seconds.
                client.SslStream.ReadTimeout  = 200;
                client.SslStream.WriteTimeout = 200;

                // Write a message to the client.
                byte[] message = Encoding.UTF8.GetBytes("Hello from the server.<EOF>");
                Console.WriteLine("Sending hello message.");
                client.SslStream.Write(message);

                mTcpClients.Add(client);
            }
            catch (AuthenticationException e)
            {
                client.SslStream.Close();
                client.Client.Close();
                return;
            }
        }
Пример #2
0
        /// <summary>
        /// This override is used to create the listening port.
        /// </summary>
        public override void Start()
        {
            mConnection        = new TcpTlsConnection();
            mConnection.Client = new TcpClient();
            mConnection.Client.Connect(EndPoint);
            var stream = mConnection.Client.GetStream();

            if (SslProtocolLevel == SslProtocols.None)
            {
                mConnection.DataStream = stream;
            }
            else
            {
                mConnection.SslStream = new SslStream(stream, false, ValidateServerCertificate);

                // The server name must match the name on the server certificate.
                try
                {
                    mConnection.SslStream.AuthenticateAsClient(EndPoint.Address.ToString());
                }
                catch (AuthenticationException e)
                {
                    mConnection.Client.Close();
                    return;
                }

                mConnection.DataStream = mConnection.SslStream;
            }
        }
        private async Task ClientRead(TcpTlsConnection client)
        {
            if (!client.SslStream.CanRead)
            {
                return;
            }

            //int length = await client.SslStream.ReadAsync();
        }
Пример #4
0
        private async Task ClientRead(TcpTlsConnection client)
        {
            if (!client.DataStream.CanRead)
            {
                return;
            }

            int length = await client.DataStream.ReadAsync(client.Buffer, 0, client.Buffer.Length);
        }
 private async Task ClientClose(TcpTlsConnection client)
 {
 }
Пример #6
0
 private async Task ClientClose(TcpTlsConnection client)
 {
     client.DataStream.Flush();
     client.DataStream.Close();
 }