Beispiel #1
0
        public Socket(IPAddress address, int port, Func <X509Certificate, X509Chain, SslPolicyErrors, bool> certificateValidationCallback)
        {
            //----------------------------------
            // certificate validation callback
            //----------------------------------

            this.certificateValidationCallback = certificateValidationCallback;

            this.socket = new System.Net.Sockets.Socket(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

            //---------------------
            // readable
            //---------------------
            this.received = 0;

            this.closed = false;

            this.paused = true;

            //---------------------
            // writeable
            //---------------------

            this.commands = new Queue <Command>();

            this.closed = false;

            this.writing = false;

            this.ended = false;

            IO.Connect(this.socket, address, port, (exception0) =>
            {
                if (exception0 != null)
                {
                    if (this.OnError != null)
                    {
                        this.OnError(exception0);
                    }

                    return;
                }

                var networkstream = new NetworkStream(this.socket);

                this.stream = new SslStream(networkstream, false, (sender, certificate, chain, errors) => {
                    return(this.certificateValidationCallback(certificate, chain, errors));
                }, null);

                IO.AuthenticateAsClient(this.stream, "localhost", (exception2) => {
                    if (exception2 != null)
                    {
                        if (this.OnError != null)
                        {
                            this.OnError(exception2);
                        }

                        return;
                    }

                    if (this.OnConnect != null)
                    {
                        this.OnConnect();
                    }

                    if (this.ondata != null)
                    {
                        this.Resume();
                    }
                });
            });
        }