Exemple #1
0
        private void ShowClientForm(TcpClient tcpClient)
        {
            if (InvokeRequired)
            {
                BeginInvoke((MethodInvoker) delegate
                {
                    ShowClientForm(tcpClient);
                });
                return;
            }

            Stream stream;

            if (useSSLListener.Checked)
            {
                SslStream ssls = new SslStream(tcpClient.GetStream(),
                                               true, ValidateCertificate);
                X509Certificate2 cert = new X509Certificate2(pfxPath.Text, "");
                ssls.AuthenticateAsServer(cert, false, SslProtocols.Tls12, false);
                stream = ssls;
            }
            else
            {
                stream = tcpClient.GetStream();
            }

            Form newForm = new TcpClientTool.MainForm(tcpClient, stream);

            newForm.Text = "TCP Client " + (++clientNum);
            newForm.Show(this);
        }
Exemple #2
0
        private void ShowClientForm(TcpClient tcpClient)
        {
            Stream stream;

            if (useSSLListener.Checked)
            {
                SslStream ssls = new SslStream(tcpClient.GetStream(), true,
                                               (sender, certificate, chain, sslPolicyErrors) =>
                {
                    return(true);
                });
                X509Certificate2 cert;
                try
                {
                    cert = new X509Certificate2(pfxPath.Text, pfxPassphrase.Text);
                }
                catch (CryptographicException ex)
                {
                    MessageBox.Show(this, ex.Message, this.Text);
                    return;
                }
                try
                {
                    ssls.AuthenticateAsServer(cert,
                                              requestClientCertificate.Checked, SslProtocols.Tls12,
                                              false);
                }
                catch (IOException)
                {
                    return;
                }
                stream = ssls;
            }
            else
            {
                stream = tcpClient.GetStream();
            }

            int  value   = Interlocked.Increment(ref clientNum);
            Form newForm = new TcpClientTool.MainForm(tcpClient, stream)
            {
                Text = "TCP Client " + (value)
            };

            newForm.Show(this);
        }
Exemple #3
0
        private void ShowClientForm(TcpClient tcpClient)
        {
            if (InvokeRequired)
            {
                BeginInvoke((MethodInvoker)delegate
                {
                    ShowClientForm(tcpClient);
                });
                return;
            }

            Stream stream;

            if (useSSLListener.Checked)
            {
                SslStream ssls = new SslStream(tcpClient.GetStream(),
                    true, ValidateCertificate);
                X509Certificate2 cert = new X509Certificate2(pfxPath.Text, "");
                ssls.AuthenticateAsServer(cert);
                stream = ssls;
            }
            else
            {
                stream = tcpClient.GetStream();
            }

            Form newForm = new TcpClientTool.MainForm(tcpClient, stream);
            newForm.Text = "TCP Client " + (++clientNum);
            newForm.Show(this);
        }