private void serialiseResponse()
    {
        byte[] responseHeader = new byte[2];
        byte[] responsePayload;
        
        // set the bits for the first byte
        responseHeader[0] = 0;
        responseHeader[1] = 0;
        if (FIN)
            responseHeader[0] = (byte) (responseHeader[0] | (byte) (1 << 7) );
        if (RSV1)
            responseHeader[0] = (byte) (responseHeader[0] | (byte) (1 << 6) );
        if (RSV2)
            responseHeader[0] = (byte) (responseHeader[0] | (byte) (1 << 5) );
        if (RSV3)
            responseHeader[0] = (byte) (responseHeader[0] | (byte) (1 << 4) );
        responseHeader[0] = (byte) (responseHeader[0] | (byte) (opcode) );
        System.out.println("First byte of response. " + responseHeader[0]);
        
        // set the payload length
        if (payloadSize <= 125)
        {
            responseHeader[1] = (byte) payloadSize;
            responsePayload = new byte[0];
        }
        else if (payloadSize <= 65535)
        {
            responseHeader[1] = (byte) 126;
            responsePayload = new byte[2];
            responsePayload[0] = (byte) (payloadSize >> 8);
            responsePayload[1] = (byte) (payloadSize & 255);
        }
        else // TODO handle payloads over 65535 bytes
        {
            responsePayload = new byte[0];
        }
    
        response = new byte[(int) (2 + responsePayload.length + message.length)];
        for (int i=0; i<2; i++)
        {
            response[i] = responseHeader[i];
        }
        
        // append
        int i;
        for (i=0; i<responsePayload.length; i++)
        {
            response[2+i] = responsePayload[i];
        }
        int payloadStart = 2 + responsePayload.length;
        
        for (i=0; i<message.length; i++)
        {
            response[payloadStart + i] = message[i];
        }
        
    }