import java.rmi.*;
public class HelloClient {
    public static void main(String[] args) {
        //    在服务器端设置安全机制         
        /*
            if (System.getSecurityManager() == null) {
                System.setSecurityManager(new RMISecurityManager()); 
            }
         */      
        /* 默认为本地主机和默认端口 */
        String host = "localhost:1199";
        /* 带输入参数时,将host设置为指定主机 */
        if (args.length > 0)
             host = args[0];
        try {
            /* 根据指定的URL定位远程实现对象 */
            /* “h”是一个标识符,我们将用它指向实现“Hello”接口的远程对象 */
			System.out.println(host+"****");
             Hello h = (Hello) Naming.lookup("rmi://" + host + "/HelloServer");
             
            System.out.println("实现“Hello”接口的远程对象: " + h);
            System.out.println("我在客户端,开始调用RMI服务器端的'sayHello'方法");
            System.out.println("欢迎,   " + h.sayHello("javamxj blog"));
         } catch (Exception ex) {
            System.out.println("错误 " + ex);
         }
     }
}
最近下载更多
wjkwmk  LV2 2023年11月13日
Amomunmu  LV1 2022年12月12日
wyx065747  LV67 2022年3月9日
wxd1997  LV13 2022年3月9日
wangcheng1020  LV1 2022年1月9日
penruins  LV1 2020年11月10日
2929737994  LV1 2020年10月13日
451573589  LV2 2020年7月5日
assoooim  LV1 2020年7月3日
zjt123  LV1 2019年11月24日
最近浏览更多
flygrass  LV12 2023年12月5日
wjkwmk  LV2 2023年11月13日
skiler  LV4 2023年9月23日
Amomunmu  LV1 2022年12月12日
zhos0212  LV19 2022年7月11日
陈小灏  LV14 2022年5月23日
萌了个乖乖  LV12 2022年5月20日
唯一&Mike  LV3 2022年5月1日
wyx065747  LV67 2022年3月9日
wxd1997  LV13 2022年3月9日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友