System.Net.Security.SslStream.EndRead C# (CSharp) Method

EndRead() public method

public EndRead ( IAsyncResult asyncResult ) : int
asyncResult IAsyncResult
return int
        public override int EndRead(IAsyncResult asyncResult)
        {
            return _sslState.SecureStream.EndRead(asyncResult);
        }

Usage Example

Example #1
0
        static void Main(string[] args)
        {
            MySocket socket = new MySocket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
            IPEndPoint iep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8888);
            socket.Connect(iep);
            MyNetworkStream stream = new MyNetworkStream(socket);
            SslStream sslStream = new SslStream(stream,false,new RemoteCertificateValidationCallback(ValidateServerCertificate),null );
            string msg = "hellodsffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffsdf,sdfwewwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwfawwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww";
            byte[] data = Encoding.UTF8.GetBytes(msg);
            byte[] packet = new byte[6 + data.Length];
            byte[] lengthBytes = data.Length.ToCustomerBytes();
            Buffer.BlockCopy(lengthBytes, 0, packet, 2, lengthBytes.Length);
            Buffer.BlockCopy(data, 0, packet, 6, data.Length);
            sslStream.AuthenticateAsClient("127.0.0.1");
            Client client = new Client(sslStream);

            byte[] head = new byte[6];
            int contentLength = 50;
            byte[] contentLengthBytes = contentLength.ToCustomerBytes();
            Array.Copy(contentLengthBytes, 0, head, 2, contentLengthBytes.Length);
            client.Write(head);

            Thread.Sleep(1000);

            int firstPart = 25;
            client.Write(new byte[firstPart]);

            Thread.Sleep(1000);
            client.Write(new byte[contentLength - firstPart]);

            byte[] buff = new byte[1024];
            sslStream.BeginRead(buff, 0, buff.Length, ar =>
                {
                    int len=sslStream.EndRead(ar);
                    Console.WriteLine(len);
                }, null);
            Console.Read();
        }