예제 #1
0
        private bool createConn(Srv s)
        {
            try
            {
                _url = s.url;

                conn.open(s, _options.Timeout);

                if (_pending != null && _bw != null)
                {
                    // flush to the pending buffer;
                    try
                    {
                        // Make a best effort, but this shouldn't stop
                        // conn creation.
                        _bw.Flush();
                    }
                    catch (Exception) { }
                }

                _bw = conn.getWriteBufferedStream(Defaults.defaultBufSize);
                _br = conn.getReadBufferedStream();
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
예제 #2
0
        internal void open(Srv s, int timeoutMillis)
        {
            lock (mu)
            {
                // If a connection was lost during a reconnect we
                // we could have a defunct SSL stream remaining and
                // need to clean up.
                if (sslStream != null)
                {
                    try
                    {
                        sslStream.Dispose();
                    }
                    catch (Exception) { }
                    sslStream = null;
                }

#if NET45
                client = new TcpClient(s.url.Host, s.url.Port);
#else
                client = new TcpClient();
                if (!client.ConnectAsync(s.url.Host, s.url.Port).Wait(TimeSpan.FromMilliseconds(timeoutMillis)))
                {
                    throw new FastNATSConnectionException("timeout");
                }
#endif

                client.NoDelay = false;

                client.ReceiveBufferSize = Defaults.defaultBufSize * 2;
                client.SendBufferSize    = Defaults.defaultBufSize;

                stream = client.GetStream();

                // save off the hostname
                hostName = s.url.Host;
            }
        }