synchronized public boolean handlecmd (BufferedReader din, DataOutputStream dout) {
        String[] str;
        int ret;
        String getline = null;
        boolean connectionClosed = false;
           
        try {

            getline = din.readLine();

            if(getline != null)
            {
        		//System.out.println("handlecmd: " + getline);

                str = getline.split(" ");
                if (str.length >=2) {
                    if (str[2].compareTo("reserve") == 0)
                    {
                        lm.requestCS(); // lamport mutex
                        ret = bl.breserve(str[0], str[1]);
                        lm.releaseCS();

                        if (ret == 1)
                        	dout.writeBytes(str[0] + " " + str[1] + '\n');
                        else
                        	dout.writeBytes("fail " + str[0] + " " + str[1] + '\n');

                        dout.flush();
                        mytotmsg++;
                    }
                    else if (str[2].compareTo("return") == 0)
                    {
                        lm.requestCS(); // lamport mutex
                        ret = bl.breturn(str[0], str[1]);
                        lm.releaseCS();

                        if (ret == 1)
                        	dout.writeBytes("free " + str[0] + " " + str[1] + '\n');
                        else
                        	dout.writeBytes("fail " + str[0] + " " + str[1] + '\n');

                        dout.flush();
                        mytotmsg++;
                    }
                    else if (str[2].compareTo("sync") == 0)
                    {
                        bl.bwsync(dout);
                        mytotmsg++;
                    }
                    else if (str[2].compareTo("exit") == 0)
                    {
                		//System.out.println("connection closed 3\n");

                    	connectionClosed = true;
                    }
                    else
                    {
                        // invalid command, dont send response to client
                    }
                } else {
                    // invalid command, dont send response to client            
                }
            }
        } catch (java.io.IOException e) {
        	connectionClosed = true;
            System.out.println(e);
        } finally{
            return connectionClosed;
        }
        
    }