@Override
	public byte[] receive() {

		if(!isConnected()){
			throw new ConnectionException("Socket disconnected - data cannot be received.");
		}
		
        try {
        	
        	//Create a packet to receive data into the buffer.
            DatagramPacket receivedPacket = new DatagramPacket(buffer, buffer.length);
            	
            //Receive the packet - if the timeout runs out, then this method will
            //throw an exception.
			socket.receive(receivedPacket);
			
			byte[] data = new byte[receivedPacket.getLength()];
			
			System.arraycopy(receivedPacket.getData(), 0, data, 0, data.length);
			
			return data;
			
			
		} catch(SocketTimeoutException ex){
			  return null;
						
		} catch (IOException e) {
			return null;
		}
        
	}