/**
 * This takes the packets from the outside world and transforms them into
 * UDPMessages according to our protocol. This is where the InvalidPacket
 * exception will be used. Use try catch.
 */
public class UDPMessage {

}

@@ -1,8 +1,27 @@
+import java.net.*;%0A
 /**%0A * T
@@ -237,10 +237,1953 @@
 sage
- %7B%0A%0A%7D
+%0A%7B%0A%09private ID id1;%0A%09private ID id2;%0A%09private TimeToLive timeToLive;%0A%09private byte%5B%5D message;%0A%0A%09public UDPMessage(ID id1, ID id2, TimeToLive timeToLive, String message)%0A%09%7B%0A%09%09this(id1, id2, timeToLive, message.getBytes());%0A%09%7D//UDPMessage%0A%0A%09public UDPMessage(ID id1, ID id2, TimeToLive timeToLive, byte%5B%5D message)%0A%09%7B%0A%09%09this.id1 = id1;%0A%09%09this.id2 = id2;%0A%09%09this.timeToLive = timeToLive;%0A%09%09this.message = message;%0A%09%7D//UDPMessage%0A%0A%09public UDPMessage(DatagramPacket datagramPacket)%0A%09%7B%0A%09%09byte%5B%5D data;%0A%09%09data = datagramPacket.getData();%0A%09%7D//UDPMessage%0A%0A%09public DatagramPacket getDatagramPacket()%0A%09%7B%0A%09%09return getDatagramPacket(this.message);%0A%09%7D//getDatagramPacket%0A%0A%09public DatagramPacket getDatagramPacket(String payload)%0A%09%7B%0A%09%09return getDatagramPacket(payload.getBytes());%0A%09%7D//getDatagramPacket%0A%0A%09public DatagramPacket getDatagramPacket(byte%5B%5D payload)%0A%09%7B%0A%09%09ID%09%09%09id1;%0A%09%09ID %09%09%09id2;%0A%09%09String %09%09myData;%0A%09%09TimeToLive%09ttl;%0A%09%09int%09%09%09size;%0A%09%09byte%5B%5D%09%09buffer;%0A%0A%09%09id1= ID.idFactory();%0A%09%09id2= ID.idFactory();%0A%09%09ttl= new TimeToLive(75);%0A%09%09myData = %22Hi%22;%0A%0A%09%09size = (ID.getLengthInBytes() *2) + timeToLive.getLengthInBytes() + myData.getBytes().length;%0A%09%09buffer = new byte%5Bsize%5D;%0A%0A%09%09System.arraycopy(id1.getBytes(), 0, buffer, 0, ID.getLengthInBytes());%0A%09%09System.arraycopy(id2.getBytes(), 0, buffer, 0, ID.getLengthInBytes());%0A%09%09System.arraycopy(ttl.getBytes(), 0, buffer, ID.getLengthInBytes()*2, TimeToLive.getLengthInBytes());%0A%09%09System.arraycopy(myData.getBytes(), 0, buffer, ID.getLengthInBytes()*2 + TimeToLive.getLengthInBytes(), myData.getBytes().length);%0A%09%09System.arraycopy(payload, 0, buffer, ID.getLengthInBytes()*2 + TimeToLive.getLengthInBytes(), myData.getBytes().length + myData.getBytes().length);%0A%0A%09%09return new DatagramPacket(buffer, size);%0A%0A%09%7D//getDatagramPacket%0A%0A%09public ID getID1()%7Breturn this.id1;%7D%0A%09public ID getID2()%7Breturn this.id2;%7D%0A%09public TimeToLive timeToLive()%7Breturn this.timeToLive;%7D%0A%09public byte%5B%5D getMessage()%7Breturn this.message;%7D%0A%0A%7D//class
 %0A

Update UDPMessage.java