private GuacamoleInstruction expect(GuacamoleReader reader, String opcode)
        throws GuacamoleException {

        // Wait for an instruction
        GuacamoleInstruction instruction = reader.readInstruction();
        if (instruction == null)
            throw new GuacamoleServerException("End of stream while waiting for \"" + opcode + "\".");

        // Report connection closure if server explicitly disconnects
        if ("disconnect".equals(instruction.getOpcode()))
            throw new GuacamoleConnectionClosedException("Server disconnected while waiting for \"" + opcode + "\".");

        // Pass through any received errors as GuacamoleExceptions
        if ("error".equals(instruction.getOpcode()))
            handleReceivedError(instruction);

        // Ensure instruction has expected opcode
        if (!instruction.getOpcode().equals(opcode))
            throw new GuacamoleServerException("Expected \"" + opcode + "\" instruction but instead received \"" + instruction.getOpcode() + "\".");

        return instruction;

    }
Waits for the instruction having the given opcode, returning that
instruction once it has been read. If the instruction is never read,
an exception is thrown.

Respects server control instructions that are allowed during the handshake
phase, namely {@code error} and {@code disconnect}.

@param reader
    The reader to read instructions from.

@param opcode
    The opcode of the instruction we are expecting.

@return
    The instruction having the given opcode.

@throws GuacamoleException
    If an error occurs while reading, or if the expected instruction is
    not read.
guacamole-common/src/main/java/org/apache/guacamole/protocol/ConfiguredGuacamoleSocket.java