当前位置: 技术问答>java相关
随帮我看看这段RMI程序的执行结果如过有错误告诉我哪里错了!
来源: 互联网 发布时间:2015-07-07
本文导语: 这是源代码希望大家帮我看看 接口 import java.rmi.Remote; import java.rmi.RemoteException; public interface RemoteInterface extends Remote{ String message(String message)throws RemoteException; } 客户 import java.rmi.RMISecurityManager; import java.rmi.Namin...
这是源代码希望大家帮我看看
接口
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface RemoteInterface extends Remote{
String message(String message)throws RemoteException;
}
客户
import java.rmi.RMISecurityManager;
import java.rmi.Naming;
public class RemoteClient
{
public static void main(String args[]){
System.setSecurityManager(new RMISecurityManager());
try{
RemoteInterface server = (RemoteInterface)Naming.lookup("servertext");
String serverString = server.message("hello");
}
catch(Exception e){
System.out.println("e");
}
}
}
服务器
import java.rmi.Naming;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;
public class RemoteObject extends UnicastRemoteObject implements RemoteInterface{
String name;
public RemoteObject(String name) throws RemoteException{
super();
this.name=name;
}
public String message(String message) throws RemoteException{
String returnString = name+message;
System.out.println(returnString);
return returnString;
}
public static void main(String args[]){
try{
String myName = "servertext";
RemoteObject theserver = new RemoteObject(myName);
Naming.rebind(myName,theserver);
System.out.println("ksdkfksd");
}
catch(Exception e){
System.out.println(e);
}
}
}
接口
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface RemoteInterface extends Remote{
String message(String message)throws RemoteException;
}
客户
import java.rmi.RMISecurityManager;
import java.rmi.Naming;
public class RemoteClient
{
public static void main(String args[]){
System.setSecurityManager(new RMISecurityManager());
try{
RemoteInterface server = (RemoteInterface)Naming.lookup("servertext");
String serverString = server.message("hello");
}
catch(Exception e){
System.out.println("e");
}
}
}
服务器
import java.rmi.Naming;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;
public class RemoteObject extends UnicastRemoteObject implements RemoteInterface{
String name;
public RemoteObject(String name) throws RemoteException{
super();
this.name=name;
}
public String message(String message) throws RemoteException{
String returnString = name+message;
System.out.println(returnString);
return returnString;
}
public static void main(String args[]){
try{
String myName = "servertext";
RemoteObject theserver = new RemoteObject(myName);
Naming.rebind(myName,theserver);
System.out.println("ksdkfksd");
}
catch(Exception e){
System.out.println(e);
}
}
}
|
根据QQ上你跟我说的情况来看
可能是你的rmiregistry没有执行
我门上QQ聊吧
可能是你的rmiregistry没有执行
我门上QQ聊吧