     }
 
     /**
-     * This method is strangely named, and it does two things which is
-     * bad style. Either log on to the next port, or save that the port
-     * we just logged on to was a good one.
-     */
-    protected function logonToPort (logonWasSuccessful :Boolean = false) :Boolean
+     * Attempts to logon on using the port at the specified index.
+     */
+    protected function attemptLogon (portIdx :int) :Boolean
     {
         var ports :Array = _client.getPorts();
-
-        if (!logonWasSuccessful) {
-            if (_portIdx >= ports.length) {
-                return false;
-            }
-            if (_portIdx != 0) {
-                _client.reportLogonTribulations(new LogonError(AuthCodes.TRYING_NEXT_PORT, true));
-
-                removeListeners();
-            }
-
-            // create the socket and set up listeners
-            _socket = new Socket();
-            _socket.endian = Endian.BIG_ENDIAN;
-            _socket.addEventListener(Event.CONNECT, socketOpened);
-            _socket.addEventListener(IOErrorEvent.IO_ERROR, socketError);
-            _socket.addEventListener(Event.CLOSE, socketClosed);
-
-            _frameReader = new FrameReader(_socket);
-            _frameReader.addEventListener(FrameAvailableEvent.FRAME_AVAILABLE, inputFrameReceived);
-        }
+        _portIdx = portIdx; // note the port we're about to try
+        if (_portIdx >= ports.length) {
+            return false;
+        }
+        if (_portIdx != 0) {
+            _client.reportLogonTribulations(new LogonError(AuthCodes.TRYING_NEXT_PORT, true));
+            removeListeners();
+        }
+
+        // create the socket and set up listeners
+        _socket = new Socket();
+        _socket.endian = Endian.BIG_ENDIAN;
+        _socket.addEventListener(Event.CONNECT, socketOpened);
+        _socket.addEventListener(IOErrorEvent.IO_ERROR, socketError);
+        _socket.addEventListener(Event.CLOSE, socketClosed);
+
+        _frameReader = new FrameReader(_socket);
+        _frameReader.addEventListener(FrameAvailableEvent.FRAME_AVAILABLE, inputFrameReceived);
 
         var host :String = _client.getHostname();
         var pport :int = ports[0];
         var ppidx :int = Math.max(0, ports.indexOf(pport));
         var port :int = (ports[(_portIdx + ppidx) % ports.length] as int);
 
-        if (logonWasSuccessful) {
-            _portIdx = -1; // indicate that we're no longer trying new ports
-
-        } else {
-            log.info("Connecting [host=" + host + ", port=" + port + "].");
-            _socket.connect(host, port);
-        }
+        log.info("Connecting [host=" + host + ", port=" + port + "].");
+        _socket.connect(host, port);
 
         return true;
     }

        _outStream = new ObjectOutputStream(_outBuffer);
        _inStream = new ObjectInputStream();

        _portIdx = 0;
        logonToPort();
    }

    public function logoff () :void

            }
        }

        // kick off our writer thread now that we know we're ready to write
        _writer = new Timer(1);
        _writer.addEventListener(TimerEvent.TIMER, sendPendingMessages);
        _writer.start();
