标签:add ext sys main oca comm rate clean up ring
一:基本开发步骤
二:demo(安装ice服务)
moudle Demo{
interface Printer{
void printString(string s);
};
};
2.在DOS环境下执行slice2java Printer.ice
3.引入Ice.jar包
4.定义类PrinterI并且继承_PrinterDisp
public class PrinterI extends _PrinterDisp{
private static final long serialVersionUID = -2685822703123295227L;
public void printString(String s, Ice.Current current){
System.out.println(s);
}
}
5.编写server端
public class Server{
public static void main(String[] args){
int status = 0;
Ice.Communicator ic = null;
try{
ic = Ice.Util.initialize(args);
Ice.ObjectAdapter adapter = ic.createObjectAdapterWithEndpoints("SimplePrinterAdapter", "default -p 10000");
Ice.Object object = new PrinterI();
adapter.add(object,ic.stringToIdentity("SimplePrinter") ); //servant标识符,用于在客户端连接
adapter.activate();
ic.waitForShutdown();
}catch(Ice.LocalException e){
e.printStackTrace();
status = 1;
}catch(Exception e){
System.err.println(e.getMessage());
status = 1;
}
if( ic != null){
//clean up
try{
ic.destroy();
}catch(Exception e){
System.err.println(e.getMessage());
status = 1;
}
}
System.exit(status);
}
}
6.编写client端
import panda.generated.Demo.PrinterPrx;
import panda.generated.Demo.PrinterPrxHelper;
public class Client {
/**
* @param args
*/
public static void main(String[] args) {
int status = 0;
Ice.Communicator ic = null;
try{
ic = Ice.Util.initialize(args);
Ice.ObjectPrx base = ic.stringToProxy("SimplePrinter:default -p 10000");
PrinterPrx printer = PrinterPrxHelper.checkedCast(base);
if(printer == null)
throw new Error("Invalid proxy");
printer.printString("Hello World!");
}catch (Ice.LocalException e){
e.printStackTrace();
status = 1;
}catch (Exception e){
System.err.println(e.getMessage());
status = 1;
}
if( ic != null ){
//clean up
try{
ic.destroy();
}catch (Exception e){
System.err.println(e.getMessage());
status = 1;
}
}
System.exit(status);
}
}
标签:add ext sys main oca comm rate clean up ring
原文地址:http://www.cnblogs.com/didiguo/p/6478303.html