private synchronized void recvChat() {
        try {
            if ((stealthComms == null) || (!stealthComms.recvReady()))
                return;
        } catch (IOException e) {
            if (stealthComms != null) {
                stealthComms.sendPacket(StealthNetPacket.CMD_LOGOUT);
                stealthComms.terminateSession();
            }
            stealthComms = null;
            return;
        }

        StealthNetPacket pckt = new StealthNetPacket();

        try {
            while ((pckt.command != StealthNetPacket.CMD_LOGOUT) &&
                (stealthComms.recvReady())) {
                pckt = stealthComms.recvPacket();
                switch (pckt.command) {
                    case StealthNetPacket.CMD_MSG :
                	    chatTextBox.append(new String(pckt.data) + "\n");
                        break;
                    case StealthNetPacket.CMD_LOGOUT :
                        JOptionPane.showMessageDialog(chatFrame,
                            "Chat session terminated at other side.",
                            "StealthNet", JOptionPane.INFORMATION_MESSAGE);
                        stealthComms.terminateSession();
                        stealthComms = null;
                        break;
                    default :
                        System.out.println("unrecognised command");
               }
            }
        } catch (Exception e) {
            System.err.println("error running client thread");
            e.printStackTrace();
        }
    }