@version $Revision: 1.5 $
*/
public class UcastTest {
public static void main(String args[]) {
DatagramSocket sock;
DatagramPacket packet;
byte[] buf=new byte[0];
boolean receiver=true;
String val;
InetAddress receiver_addr=null, sender_addr=null;
int receiver_port=0, sender_port=0;
for(int i=0; i < args.length; i++) {
val=args[i];
if("-help".equals(val)) {
help();
return;
}
if("-sender".equals(val)) {
receiver=false;
continue;
}
if("-sender_addr".equals(val)) {
try {
sender_addr=InetAddress.getByName(args[++i]);
sender_port=Integer.parseInt(args[++i]);
continue;
}
catch(Exception e) {
System.err.println(e);
help();
return;
}
}
if("-receiver".equals(val)) {
receiver=true;
try {
receiver_addr=InetAddress.getByName(args[++i]);
receiver_port=Integer.parseInt(args[++i]);
}
catch(Exception e) {
System.err.println(e);
help();
return;
}
continue;
}
help();
}
try {
if(receiver) {
sock=new DatagramSocket(receiver_port, receiver_addr);
System.out.println("Socket=" + sock.getLocalAddress() + ':' + sock.getLocalPort());
System.out.println("starting as receiver");
receiverLoop(sock);
}
else {
if(sender_addr != null && sender_port > 0)
sock=new DatagramSocket(sender_port, sender_addr);
else
sock=new DatagramSocket();
System.out.println("Socket=" + sock.getLocalAddress() + ':' + sock.getLocalPort());
System.out.println("starting as sender");
senderLoop(sock);
}
}
catch(Exception e) {