public void run() {
    try {
      byte[] buffer = new byte[1024];
      StringBuffer lastMessage = new StringBuffer();
      int len;
      int lastPos;

      while (!disconnected && (len = input.read(buffer)) != -1) {
	lastPos = 0;
	for (int i = 0; i < len; i++) {
	  if (buffer[i] == 0) {
	    String msg = new String(buffer, lastPos, i - lastPos);
	    lastMessage.append(msg);
	    handleMessage(lastMessage.toString());
	    lastMessage = new StringBuffer();
	    lastPos = i + 1;
	    /* To test if the server handles agents that does not read
	       if (msg.indexOf("bidInfo") > 0) {
	       System.out.println("Reader sleeping...");
	       Thread.sleep(200000);
	       }
	    */
	  }
	}
	if (lastPos < len) {
	  lastMessage.append(new String(buffer, lastPos, len - lastPos));
	}
      }
    } catch (Throwable e) {
      log.log(Level.SEVERE, "could not read:", e);
    } finally {
      agent.reset(0, this);
    }
  }