DatagramPacket send_packet, recv_packet;
byte[] send_buf;
byte[] recv_buf=new byte[2100];
if(local) {
MulticastSocket send_sock=new MulticastSocket(PORT);
send_sock.setTrafficClass(8);
MulticastSocket recv_sock=new MulticastSocket(PORT);
recv_sock.joinGroup(GROUP);
recv_packet=new DatagramPacket(recv_buf, 0, recv_buf.length);
for(int i=0; i < 10; i++) {
start=System.currentTimeMillis();
send_buf=Util.objectToByteBuffer(start);
send_packet=new DatagramPacket(send_buf, 0, send_buf.length, GROUP, PORT);
send_sock.send(send_packet);
recv_sock.receive(recv_packet);
start=((Long)Util.objectFromByteBuffer(recv_buf, recv_packet.getOffset(), recv_packet.getLength())).longValue();
System.out.println("took " + (System.currentTimeMillis() - start) + " ms");
Util.sleep(1000);
}
return;
}
if(sender) {
MulticastSocket send_sock=new MulticastSocket(PORT);
send_sock.setTrafficClass(8);
for(int i=0; i < 10; i++) {
start=System.currentTimeMillis();
send_buf=Util.objectToByteBuffer(start);
send_packet=new DatagramPacket(send_buf, 0, send_buf.length, GROUP, PORT);
send_sock.send(send_packet);
Util.sleep(1000);
}
}
else {
MulticastSocket recv_sock=new MulticastSocket(PORT);
recv_sock.joinGroup(GROUP);
recv_packet=new DatagramPacket(recv_buf, 0, recv_buf.length);
System.out.println("receiver started");
for(;;) {
recv_sock.receive(recv_packet);
start=((Long)Util.objectFromByteBuffer(recv_buf, recv_packet.getOffset(), recv_packet.getLength())).longValue();
System.out.println("took " + (System.currentTimeMillis() - start) + " ms");
}
}
}