public JFastRequest(Socket socket)
        throws IOException, JFastException
    {
        this.socket = socket;
        properties = new Properties();
        data = new byte[0];
        input = socket.getInputStream();
        output = socket.getOutputStream();
        
        JFastMessage message = null;        
        do
        {               
            message = new JFastMessage(input);
            switch(message.type)
            {                    
                case JFast.BEGIN_REQUEST:
                    
                    if(this.requestId != 0)
                    {
                        // tell the webserver that we won't handle 
                        // multiplexed connections
                        JFastMessage cancel = new JFastMessage(JFast.VERSION,
                            JFast.END_REQUEST,message.requestId);
                        cancel.setContent(createEndRequestBody(0,
                            JFast.NO_MULTIPLEX_CONNECTION));
                        cancel.write(output);
                    }
                    else
                    {
                        this.requestId = message.requestId;
                        this.flags = message.content[2] & 0xff;
                        this.role = ((message.content[0] & 0xff) << 8) | 
                                     (message.content[1] & 0xff);                        
                    }
                    
                    continue;
                    
                case JFast.STDIN:
                    appendData(message.content);
                    continue;
                    
                case JFast.PARAMETERS:
                    collectParameters(message.content);
                    continue;                         
            }                        
        }
        // an empty STDIN means it's our turn
        while(message.type != JFast.STDIN || message.content.length != 0);
        
        out = new PrintStream(new BufferedOutputStream(
            new JFastOutput(output,requestId),OUTPUT_BUFFER_SIZE));
        error = new PrintStream(new BufferedOutputStream(
            new JFastErrorOutput(output,requestId),OUTPUT_BUFFER_SIZE));
    }