HelloServer.java
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:1k
源码类别:
Java编程
开发平台:
Java
- package bible.rmi.example1;
- import weblogic.rmi.*;
- import java.rmi.*;
- /**
- * HelloServer is a remote server that can registers itself via Naming and
- * wait for clients to call its remote method, sayHello.
- */
- public class HelloServer implements HelloInterface {
- /**
- * When remote client's call say hello, respond with a greeting, also
- * pushs a message to standard out that this method has been called.
- * @returns A greeting from the implementing server.
- * @throws RemoteException
- */
- public String sayHello() throws java.rmi.RemoteException {
- System.out.println("HelloServer.sayHello() has been remotely invoked.");
- return "Hello, remote world!!";
- }
- /**
- * Main method instanciates a server, registers itself with a bind, and
- * waits for clients to call the remote method sayHello.
- * @param argv
- */
- public static void main(String[] argv) {
- try {
- HelloServer obj = new HelloServer();
- weblogic.rmi.Naming.rebind("HelloServer", obj);
- System.out.println("HelloServer was created and bound in the registry "
- + "to the name HelloServer");
- } catch (Exception e) {
- System.out.println("HelloServer error: " + e.getMessage());
- e.printStackTrace();
- }
- }
- }