Java知识分享网 - 轻松学习从此开始!    

Java知识分享网

Java1234官方群25:java1234官方群17
Java1234官方群25:838462530
        
SpringBoot+SpringSecurity+Vue+ElementPlus权限系统实战课程 震撼发布        

最新Java全栈就业实战课程(免费)

springcloud分布式电商秒杀实战课程

IDEA永久激活

66套java实战课程无套路领取

锋哥开始收Java学员啦!

Python学习路线图

锋哥开始收Java学员啦!
当前位置: 主页 > Java文档 > Java基础相关 >

Java RMI Tutorial PDF 下载


分享到:
时间:2021-07-21 07:31来源:http://www.java1234.com 作者:转载  侵权举报
Java RMI Tutorial PDF 下载
失效链接处理
Java RMI Tutorial PDF 下载

本站整理下载:
提取码:qgyc 
 
 
相关截图:
 
主要内容:

Using Java RMI at Colby
Fall 2008
Stephanie Taylor
“The Java Remote Method Invocation (RMI) system allows an object running in one Java virtual machine
to invoke methods on an object running in another Java virtual machine.”
(http://java.sun.com/docs/books/tutorial/rmi/overview.html)
This document describes my experience running, modifying, and re-running a distributed version of
“Hello World” from http://java.sun.com/j2se/1.5.0/docs/guide/rmi/hello/hello-world.html. The basic
setup for the “Hello World” example (and for any simple client-server example) is this: There are two
machines - one we will call the server (lowercase), the other we will call the client (lowercase). 1 The
server machine will run a Java program called Server (title case) and the client machine will run a java
program called Client (title case). Server is a Remote object, i.e. an object with methods that can
be invoked by Client via an internet/intranet connection. To initiate the communication between the
server and client, a third program – the RMI registry must be running on the server. See Figure 1.
Figure 1: The rmiregistry and Server run on the server. The Client runs on the client. The registry is
used to initiate communication between Client and Server, but they then communicate “directly”
(this “direct” communication may be mediated by a web server).
Hello World Code
The code for the “Hello World” example is in a package example.hello. This means that the
.class files must be placed into a directory example/hello. I created a directory
/Users/srtaylor/Documents/CS336/java_rmi for all of the examples in this tutorial. I then
created a subdirectory example/hello for this example and placed Hello.java, Client.java, and
Server.java in it.
Let’s look at the code. Here is Hello.java:
1 In a client-server model there may be (and often is) more than one client. Each client is identical to
every other, so I simply refer to “the” client here.
package example.hello;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Hello extends Remote {
String sayHello() throws RemoteException;
}
It declares that it is in the example.hello package and imports the Remote and
RemoteException classes. The Hello interface extends the Remote class. This means that any
class implementing Hello will be a Remote class. Any method in a Remote object must throw a
RemoteException. Thus the method sayHello is declared as one that has the potential to throw
a RemoteException.
Let’s move on to Server.java. Here is its code:
package example.hello;
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class Server implements Hello {
public Server() {}
public String sayHello() {
System.out.println("Running sayHello()");
return "Hello, world!";
}
public static void main(String args[]) {
int rport = (args.length < 1) ? 8080 : Integer.parseInt(args[0]);
try {
Server obj = new Server();
Hello stub = (Hello) UnicastRemoteObject.exportObject(obj,0);
// Bind the remote object's stub in the registry
Registry registry = LocateRegistry.getRegistry(rport);
registry.rebind("Hello", stub);
System.err.println("Server ready");
} catch (Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
}
}
First, we noti

 

------分隔线----------------------------

锋哥公众号


锋哥微信


关注公众号
【Java资料站】
回复 666
获取 
66套java
从菜鸡到大神
项目实战课程

锋哥推荐