XenAPI.HTTP.ConnectStream C# (CSharp) 메소드

ConnectStream() 공개 정적인 메소드

This function will connect a stream to a uri (host and port), negotiating proxies and SSL
public static ConnectStream ( Uri uri, IWebProxy proxy, bool nodelay, int timeout_ms ) : Stream
uri System.Uri
proxy IWebProxy
nodelay bool
timeout_ms int Timeout, in ms. 0 for no timeout.
리턴 Stream
        public static Stream ConnectStream(Uri uri, IWebProxy proxy, bool nodelay, int timeout_ms)
        {
            IMockWebProxy mockProxy = proxy != null ? proxy as IMockWebProxy : null;
            if (mockProxy != null)
                return mockProxy.GetStream(uri);

            Stream stream;
            bool useProxy = proxy != null && !proxy.IsBypassed(uri);

            if (useProxy)
            {
                Uri proxyURI = proxy.GetProxy(uri);
                stream = ConnectSocket(proxyURI, nodelay, timeout_ms);
            }
            else
            {
                stream = ConnectSocket(uri, nodelay, timeout_ms);
            }

            try
            {
                if (useProxy)
                {
                    string line = String.Format("CONNECT {0}:{1} HTTP/1.0", uri.Host, uri.Port);

                    WriteLine(line, stream);
                    WriteLine(stream);

                    ReadHttpHeaders(ref stream, proxy, nodelay, timeout_ms);
                }

                if (UseSSL(uri))
                {
                    SslStream sslStream = new SslStream(stream, false,
                        new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
                    sslStream.AuthenticateAsClient("", null, SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12, true);

                    stream = sslStream;
                }

                return stream;
            }
            catch
            {
                stream.Close();
                throw;
            }
        }