java RMI

来源:互联网 发布:php 去掉斜线 编辑:程序博客网 时间:2024/05/21 08:00
public interface MyRemote extends Remote {public String sayHello() throws RemoteException;}

public class MyRemoteClient {public static void main(String[] args) {new MyRemoteClient().go();}public void go() {try {MyRemote service = (MyRemote) Naming.lookup("rmi://129.168.10.107/RemoteHello");String s = service.sayHello();System.out.println(s);} catch (Exception e) {e.printStackTrace();}}}

public class MyRemoteImpl extends UnicastRemoteObject implements MyRemote {protected MyRemoteImpl() throws RemoteException {super();}private static final long serialVersionUID = -1667780102301508304L;@Overridepublic String sayHello() throws RemoteException {return "From the server, 'Hello...'";}public static void main(String[] args) {Remote service;try {service = new MyRemoteImpl();Naming.rebind("RemoteHello", service);} catch (Exception e) {e.printStackTrace();}}}

原创粉丝点击