public void processPackets() {
	if(left())
	    return;
	try {
	    DataInputStream din = getInputStream();
	    if (din.available() >= 2) {
		short id = din.readShort();
		Packet p = Packet.newPacket(id, this);
		if (p != null)
		    p.handlePacket();
		else
		    kick("Invalid Packet");
	    }
	    if (getSocket().isClosed())
		leave("Socket closed");
	    long now = System.currentTimeMillis();
	    if(lastPacket == 0)
		lastPacket = System.currentTimeMillis();
	    if (now - this.getLastPacketTime() >= 2100) {
		PacketHeartbeat heartbeat = new PacketHeartbeat(this);
		heartbeat.response = false;
		byte[] bytes = new byte[43];
		new Random().nextBytes(bytes);
		heartbeat.payload = bytes;
		heartbeat.send();
	    }
	} catch (Exception e) {
	    leave(e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage());
	}
    }