public static int sendAndWait(byte[] b, int num, int t, InetAddress ip,
			Integer p, DatagramSocket d) throws IOException {
		int ack = 0;
		byte[] receiveAck = new byte[3];
		try {
			// Send packet
			DatagramPacket packet = new DatagramPacket(b, b.length, ip, p);
			d.send(packet);

			// Wait for acknowledgment
			DatagramPacket receivePacket = new DatagramPacket(receiveAck,
					receiveAck.length);
			d.setSoTimeout(t);
			d.receive(receivePacket);
			if (Utilities.bytesToInt(receiveAck[0], receiveAck[1]) == num) {
				ack = (int) receiveAck[2];
			} else {
				ack = -1;
			}

		} catch (SocketException e) {
			// Socket timed out
			ack = 0;

		} catch (IOException e) {
			ack = 0;

		}

		return ack;
	}