private void disconnect()
    {
        if(clientStatus == 2)
        {
            clientStatus = 3;
            try
            {
                socket.close();
            }
            catch(IOException ioexception)
            {
                logMessage("IO exception trying to disconnect.");
            }
            finally
            {
                reader = null;
                writer = null;
                logMessage("Connection closed.");
                clientStatus = 0;
            }
        } else
        {
            switch(clientStatus)
            {
            case 0: // '\0'
                logMessage("Cannot close connection; not connected.");
                break;

            case 1: // '\001'
                logMessage("Cannot close connection; currently trying to connect.");
                break;

            case 3: // '\003'
                logMessage("Cannot close connection; currently trying to close it.");
                break;

            case 2: // '\002'
            default:
                logMessage("Got unknown clientStatusCode: " + clientStatus);
                break;
            }
        }
    }