public void clientRead(){
		
		this.bnum = new BlockNumber();
		this.bnum.increment();	
		byte[] block = bnum.getCurrent();
		this.counter = 1;
		
		try {
			BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(dir));
			for(;;){
				int length;
				byte[] packet = getBlock(bnum.getCurrent());
				
				if(packet == null) {
					out.close();
					return;
				}
				byte[] temp = new byte[packet.length-4];
				
				block[0] = packet[2];
				block[1] = packet[3];
				System.arraycopy(packet, 4,temp, 0, packet.length-4);
				for(length = 4; length < temp.length; length++) {
					//System.out.print(temp[length]+","); // Used to check incoming byte array for debugging
					if (temp[length] == 0) break;
				}
				
				//check the free space on current partition is less than the length of the received data
				//if true, then there are not enough available space, therefore should throw an error and exit
				long partition = (new File(dir).getFreeSpace());
				if(partition < (long)length){
					System.out.println("Need " + length + " bytes of free space, but current partition only has " + partition + " bytes.");
					System.out.println("Client will exit.");
					
					//send ERROR 3
					//TO BE IMPLEMENTED
					byte [] error3 = {(byte)0, (byte)5, (byte)0, (byte)3};
					
					DatagramPacket errorPacket = new DatagramPacket(error3, error3.length,this.serverIP, sendPort);
					sendReceiveSocket.send(errorPacket);
					
					System.out.println("Transfer complete");
					//exit
					out.close();
					return;
				}
				
				try {
					out.write(temp,0,length);
				}catch(IOException e) {
					String message = "File too large";
					System.out.println(message);
					byte data[] = new byte[4+message.getBytes().length+1];
					data[0] = 0;
					data[1] = 5;
					data[2] = 0;
					data[3] = 1;
					System.arraycopy(message.getBytes(), 0, data, 4, message.getBytes().length);
					data[data.length-1] = 0;
					this.sendReceiveSocket.send(new DatagramPacket(data,data.length,this.serverIP,this.sendPort));
					out.close();
					return;
				}
				System.out.println("Sending ack");
				sendAck(block);					
				
				System.out.println("length is: "+length);
				
				
				if(length<MESSAGE_SIZE) {
					out.close();
					break;
				}
				
				this.bnum.increment();				
			}
		}  catch (IOException e) {
			System.out.println("File Read Error:");
			e.printStackTrace();
			 System.exit(1);
			return;
		}
	}