import lava.net.common.*; import lava.net.mmp.*; import java.util.*; import java.net.*; /** * **/ public class MMPTest implements MMPPacketManager { /** * **/ private MMPMessageCenter m = null; /** * **/ public String getGreetingBody(UNA remote, UNA local) { return null; } /** * **/ public void manage(MMPPacket p) { System.out.print("Got Packet from " + p.getRemote()); String[] names = m.getVars(p.getRemote(),p.getLocal()); if(names.length <= 0) System.out.print(" (no variables)"); if(p.getStringBody() == null || p.getStringBody().length() <= 0) System.out.print(" (empty body)"); System.out.println(); if(names.length > 0) { System.out.print(" Vars: "); int i = 0; for(;i < names.length - 1;++i) System.out.print(names[i] + ", "); System.out.println(names.length == 0 ? "" : names[i]); } if(p.getStringBody() != null && p.getStringBody().length() > 0) System.out.println(" Body: " + p.getStringBody()); m.send(p.getRemote(),p.getLocal(),p); } /** * **/ public void error(MMPException e, UNA remote, UNA local, MMPPacket p) { System.out.println("Got Error: " + e + // ", from " + (remote != null ? remote.toString() : "(null)") + // " to " + (local != null ? local.toString() : "(null)") + // ": " + p); } /** * **/ public static void main(String[] args) { MMPTest t = new MMPTest(); if(args.length > 0) if(args.length == 1 && // (args[0].equals("-n") || args[0].equals("--nolisten"))) t.m = new MMPMessageCenter(t,false); else { UNA[] listen = new UNA[args.length]; for(int i = 0;i < args.length;++i) listen[i] = new UNA(args[i]); t.m = new MMPMessageCenter(t,listen); } else t.m = new MMPMessageCenter(t); t.m.answerCounterWithCounter(true); System.out.print("MMP Message Center "); UNA[] listen = t.m.getListenLocations(); if(listen.length <= 0) System.out.println("does not listen!"); else System.out.println("is listening on:"); for(int i = 0;i < listen.length;++i) System.out.println(" " + listen[i].toString()); } }