当前位置: 技术问答>java相关
绝对高分--java中rmi的问题
来源: 互联网 发布时间:2015-05-25
本文导语: 诸位大虾: 本人使用java由一段时间了,但刚刚接触rmi, 在使用过程中遇到了以下两个问题 1.执行rmiregistry命令后,计算机犹如死机,毫无反应,不知为何 2.执行rmi服务端程序后: 爆出以下异常: Exception in...
诸位大虾:
本人使用java由一段时间了,但刚刚接触rmi,
在使用过程中遇到了以下两个问题
1.执行rmiregistry命令后,计算机犹如死机,毫无反应,不知为何
2.执行rmi服务端程序后:
爆出以下异常:
Exception in thread "main" java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested
exception is:
java.net.ConnectException: Connection refused: no further information
java.net.ConnectException: Connection refused: no further information
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:312)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:125)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:112)
at java.net.Socket.(Socket.java:273)
at java.net.Socket.(Socket.java:100)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:2
5)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:1
20)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:499)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:190)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:174)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:318)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:160)
at RemoteServer1.(RemoteServer1.java:8)
at RemoteServer1.main(RemoteServer1.java:11)
程序源码:
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.net.*;
public class RemoteServer1{
public RemoteServer1() throws Exception{
System.setSecurityManager(new RMISecurityManager());
LocateRegistry.createRegistry(1099);
RemoteMethodInterface1 remoteObject=new RemoteMethodClass1();
Naming.rebind("rmi://localhost:1099/RemoteService",remoteObject);
}
public static void main(String[] args)throws Exception{
new RemoteServer1();
}
}
本人使用java由一段时间了,但刚刚接触rmi,
在使用过程中遇到了以下两个问题
1.执行rmiregistry命令后,计算机犹如死机,毫无反应,不知为何
2.执行rmi服务端程序后:
爆出以下异常:
Exception in thread "main" java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested
exception is:
java.net.ConnectException: Connection refused: no further information
java.net.ConnectException: Connection refused: no further information
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:312)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:125)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:112)
at java.net.Socket.(Socket.java:273)
at java.net.Socket.(Socket.java:100)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:2
5)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:1
20)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:499)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:190)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:174)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:318)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:160)
at RemoteServer1.(RemoteServer1.java:8)
at RemoteServer1.main(RemoteServer1.java:11)
程序源码:
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.net.*;
public class RemoteServer1{
public RemoteServer1() throws Exception{
System.setSecurityManager(new RMISecurityManager());
LocateRegistry.createRegistry(1099);
RemoteMethodInterface1 remoteObject=new RemoteMethodClass1();
Naming.rebind("rmi://localhost:1099/RemoteService",remoteObject);
}
public static void main(String[] args)throws Exception{
new RemoteServer1();
}
}
|
注意: LocateRegistry.createRegistry(1099);
你的rmi server自己启动 rmiregistry service, 所以你就不用执行rmiregistry了(还说人家没有反应)
你的rmi server自己启动 rmiregistry service, 所以你就不用执行rmiregistry了(还说人家没有反应)
|
注意: LocateRegistry.createRegistry(1099);
你的rmi server自己启动 rmiregistry service, 所以你就不用执行rmiregistry了(还说人家没有反应)
你的rmi server自己启动 rmiregistry service, 所以你就不用执行rmiregistry了(还说人家没有反应)
|
你第一次没有bind怎么要rebind呢
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.net.*;
public class RemoteServer1{
public RemoteServer1() throws Exception{
System.setSecurityManager(new RMISecurityManager());
LocateRegistry.createRegistry(1099);
RemoteMethodInterface1 remoteObject=new RemoteMethodClass1();
String myName="rmi://localhost:1099/RemoteService";
if (java.rmi.Naming.lookup(myName) == null)
java.rmi.Naming.bind(myName, remoteObject);
else
java.rmi.Naming.rebind(myName, remoteObject);
}
public static void main(String[] args)throws Exception{
new RemoteServer1();
}
}
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.net.*;
public class RemoteServer1{
public RemoteServer1() throws Exception{
System.setSecurityManager(new RMISecurityManager());
LocateRegistry.createRegistry(1099);
RemoteMethodInterface1 remoteObject=new RemoteMethodClass1();
String myName="rmi://localhost:1099/RemoteService";
if (java.rmi.Naming.lookup(myName) == null)
java.rmi.Naming.bind(myName, remoteObject);
else
java.rmi.Naming.rebind(myName, remoteObject);
}
public static void main(String[] args)throws Exception{
new RemoteServer1();
}
}
|
你是不是在一台没有网卡的计算机上运行的,有可能是由于你没有装tcp/ip协议,rmi可是默认基于tcp/ip协议的。