Example #1
0
 private void Disconnect(Connection conn)
 {
     lock (_stateLock)
     {
         if (_connection != null && _connection == conn)
         {
             _connection.Dispose();
             _connection = null;
             return;
         }
     }
     conn.Dispose();
 }
Example #2
0
        private Connection ConnectServer()
        {
            lock (_stateLock)
            {
                if (_connection != null)
                {
                    return _connection;
                }
                if (_processor == null)
                {
                    return null;
                }

                Connection newConn = null;
                try
                {
                    newConn = new Connection(_serverAddr, _serverPort);
                    newConn.Send(_connectMsg);
                    foreach (var sub in _subscriptions.Values)
                    {
                        SendSubscribe(newConn, sub);
                    }
                    _connection = newConn;
                }
                catch (SocketException err)
                {
                    Trace.TraceError("NATS-CLIENT-EXCEPTION: {0}", err);
                }
                catch (IOException err)
                {
                    Trace.TraceError("NATS-CLIENT-EXCEPTION: {0}", err);
                }
                finally
                {
                    if (_connection != newConn)
                    {
                        newConn.Dispose();
                    }
                }
                return _connection;
            }
        }