view src/fdl/ComDebug_Client.java @ 19:0243987383b7

Meta Protocol Engine and sample implementation of event logger. ComDebug_Client needs fixes.
author kono
date Tue, 19 Aug 2008 05:33:32 +0900
parents 609b288f47f9
children a0fd653d1121
line wrap: on
line source

package fdl;


import java.io.IOException;

/*
 * それぞれのLinda Serverのmeta protocolに接続して、順々にモニタデータを
 * 受け取って表示する。
 */
public class ComDebug_Client {

	static int id;
	static final boolean debug = false;

	public static void main(String[] args) {
		FederatedLinda fdl;
		PSXLindaInterface psx;
		String host  = "localhost";
		int port = 10000;
		int connect_num = 1;
		final String usages = "usage: ComDebug_Client [-h host -p port]";

		//引数判定
		try {
			if (args.length < 2) {
				System.err.println(usages);
			}
				
			for (int i=0; i<args.length; ++i) {
				if("-h".equals(args[i])) {
					host = (String)(args[++i]);
					System.err.println("host = "+host);
				} else {
					//System.err.println(usages);
				}
				if("-p".equals(args[i])) {
					port = Integer.parseInt(args[++i]);
					System.err.println("port = "+port);
				} else {
					//System.err.println(usages);
				}
			}
		} catch (NumberFormatException e) {
			e.printStackTrace();
		}
		
		
		try {
			PSXReply r;
		    fdl = FederatedLinda.init();
		    psx = fdl.open(host,port);
		    r = psx.in(65535);
			fdl.sync(1);
			if(debug == true){
			    System.out.println("PSXReply =>"+r.toString());
		    }

		    System.out.println("COM_DEBUG Connected.["+host+":"+port+"]");
		    psx.in(PSX.PRIVILEGED_ID_START+connect_num);
		    connect_num++;
		    while(true) {
		    	fdl.sync(1000);
		    }
		} catch (IOException nfex) {
			nfex.printStackTrace();
		    System.out.println("Faild.");
		    return;
		}
	}
}