Questions and Answers for Assignment #4:
HyperCast assignment
Q2.01: I have a problem with the sendToParent()
method?
A2.01: There was a bug in the sendToParent() method. The
problem has been fixed and updated on the website.
Solution 1: Download the updated version of the software
Solution 2: Use the method getParent(root) to get the logical
address of the node's parent and then use the method sendToNode().
Q2.02: How do I create a logical address in the DT
protocol?
A2.02: When creating a logical address for the DT protocol
from an integer pair (x,y), you need to convert the
integer pair into a byte array.
In the DT protocol, the coordinates are stored as follows:
4 bytes 4 bytes
+-----------+-----------+
| x
| y |
+-----------+-----------+
Say, you have two integers: (x,y) and want to
create a logical address. This is done as follows
I_OverlaySocket mySocket;
byte[] Result=new byte[8]
System.arraycopy(toByteArray(x),0,Result,0,4);
System.arraycopy(toByteArray(y),0,Result,4,4);
I_logicalAddress mylogicalAddress =
mySocket.createLogicalAddress(Result,0);
Where the class toByteArray
is as shown below.
|
/**
*
Converts an integer to a byte array
*
@param
value an
integer
*
@return a
byte array representing the integer
*/
public static byte[] toByteArray(int value) {
byte[] Result = new byte[4];
Result[3] = (byte) ((value >>> (8*0)) & 0xFF);
Result[2] = (byte) ((value >>> (8*1)) & 0xFF);
Result[1] = (byte) ((value >>> (8*2)) & 0xFF);
Result[0] = (byte) ((value >>> (8*3)) & 0xFF);
return Result;
} |