Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Too much message segmentation is considered harmful, partially due to the overhe

ID: 2247062 • Letter: T

Question

Too much message segmentation is considered harmful, partially due to the overhead cost caused by the header fields. The same amount of header fields has to be added to each packet, therefore, the more such packets are (i.e. the more message segmentation we perform), the more overhead costs from such header fields will be.

Now, let’s assume that everything stays the same as problem 1.b) above except that the size of each packet varies from 4kb to 2kb, to 1kb, … to 125bits. In other words, the size of each packet is cut in half (correspondingly, the number of packets gets doubled) as we go on in our experiment.

2a. Assume no overhead caused by the header fields. Write a JAVA program that produces the comparison of size of each packet vs. the end-to-end delay of the transmission of the entire message of 16 kb.

2b. .Assume the overhead caused by the header fields is 10 bits. Redo part a).

2c. Assume the overhead caused by the header fields is 20 bits. Redo part a).

I'm not really looking for a fancy answer. Just simple output through a software like JGRASP or eclipse


Explanation / Answer

String string = "My awesome string!";

byte[] buff = new byte[ string.length*2 ];

buff = string.getBytes();

...

packet = new DatagramPacket(buff, buff.length, address, port);

socket.send(packet);

byte[] buff = new byte[ 65000 ]

//file and bufferreader handle

while( ( line = bufferedReader.readLine() ) != null ){

buff = line.getBytes();

packet = new DatagramPacket(buff, buff.length, address, port);

socket.send(packet);

}

byte[] buff = new byte[250];

packet = new DatagramPacket(buff, buff.length);

socket.receive(packet);

System.out.println("GET: " + buff);

That means if I want to send an UDP packet to a server, I must find the length of the string (for example) and multiply by 2?

No. String.getBytes() already allocates a proper array of the right length:

byte[] buff = string.getBytes();

byte[] buff = null;

try {

buff = string.getBytes("UTF-8");

} catch (UnsupportedEncodingException e) {

e.printStackTrace();

}

MessageDigest md = MessageDigest.getInstance( "SHA" );

FileInputStream ios = new FileInputStream( "myfile.bmp" );

byte[] buffer = new byte[4 * 1024]; // what should this value be?

int read = 0;

while( ( read = ios.read( buffer ) ) > 0 )

md.update( buffer, 0, read );

ios.close();

md.digest();

DatagramSocket clientSocket = new DatagramSocket();
InetAddress IPAddress = InetAddress.getByName(textField.getText());
byte[] sendData = new byte[(int)myFile.length()];
FileInputStream convertToBytes = new FileInputStream(myFile);
convertToBytes.read(sendData);
convertToBytes.close();
DataGrama dataGrama = new DataGrama(0, 0, sendData);
sendData = serializeClass(dataGrama);
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9874);
clientSocket.send(sendPacket);
byte[] receiveData = new byte[50]; //<-- Here is the problem, how do I discover the size of the incoming byte array?
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
serverSocket.receive(receivePacket);

User user = (User) selectionKey.attachment();
SocketChannel socketChannel = user.getSocketChannel();
ByteBuffer readBuffer = user.getReadBuffer();
ByteBuffer lengthBuffer = user.getLengthBuffer();

while (true) {
  
if (lengthBuffer.hasRemaining()) {
socketChannel.read(lengthBuffer);
  
if (lengthBuffer.hasRemaining()) {
break;
}
} else {
  

if (readBuffer == null) {
lengthBuffer.flip();
user.setReadBuffer(ByteBuffer.allocate(lengthBuffer
.getInt()));
}
socketChannel.read(readBuffer);
  
if (readBuffer.hasRemaining()) {
break;
} else {
  

readBuffer.flip();
user.handleData();
user.setReadBuffer(null);
lengthBuffer.clear();
}
}
}


Integer a1 = 100;
Integer a2 = 100;
System.out.println(a1 == a2); // true

Integer b1 = new Integer(100);
Integer b2 = new Integer(100);
System.out.println(b1 == b2); // false

Integer c1 = 150;
Integer c2 = 150;
System.out.println(c1 == c2);

public class ResizingArrayStack<Item> {
Item[] a = new Item[1];
String s;
for (s : listOfStrings)
System.out.println(s);
Stack<Integer> s = new Stack<Integer>();
while (n > 0) {
s.push(n % 2);
n = n / 2;
}
while (!s.isEmpty())
System.out.print(s.pop());
System.out.println();
Stack<String> s = new Stack<String>();
while(!q.isEmpty())
s.push(q.dequeue());
while(!s.isEmpty())
q.enqueue(s.pop());