public void run() {
		try {
			while(!finished && !socket.isClosed()) {
				Packet packet = Packet.unpack(in);

				if(packet == null) {
					// The other side closed the connection
					break;
				}
				//System.out.println("Received packet: " + packet);

				if((packet.getFlags() & Packet.FIN) != 0) {
					gotFIN = true;
					return;
				}

				// store it
				storePacket(packet);
			}
		}catch(IOException e) {
			System.err.println("Encountered IOException when trying to receive packet.");
			//e.printStackTrace();
		}

		try {
			socket.close();
		} catch (IOException e) {
		}
		synchronized (parent) {
			if (parent != null) {
				parent.IOFinish();
			}
		}
	}