这是个普遍的rmi问题,关键是rmi默认的ip是内网那个ip,所以你得需要指定一下ip就可以了,比如你在启动你的rmi server的时候,需要在你的代码前设置一下,加入
System.setProperty("java.rmi.server.hostname","外网的ip");
System.setProperty("java.rmi.server.hostname","外网的ip");
解决方案 »
- 下面的jsp连接数据库为什么在页面啥都不显示啊
- Ext Json分页的问题
- 请问一个tomcat创建数据源的问题,我在web项目的meta-INF下配置了context-xml文件配置了jndi数据源
- socket最应该注意的有哪些???? 急!!!!!
- websphere 新手入门下载和安装问题
- spring基本概念级疑惑 SOS!!!!!!!!!
- SQL问题
- 关于class文件的放置问题
- 在网上下载了Rational Rose,安装后不知怎么注册?主要是看不懂那个安装说明文件,E文的.或者大家能不能提供一个中文版下载地址和注册方
- 求大神,tomcat只增加线程不减少线程,请问啥原因
- 初学,请问:Web Service的jws文件一定要放在项目根目录下吗?
- 我以个人的名义求助?现在上海哪个公司在招人,提供一下信息吧!
兄台帮个忙吧!!!
我在server端的程序如下
import java.net.InetAddress;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;import javax.swing.JOptionPane;import com.teamax.xgis.rmi.XPubrmi.server.xgisXPubRMIConnectionServe;
import com.teamax.xgis.rmi.XPubrmi.server.xgisXPubRMIConnectionServerSend;public class RMIMainApp
{
public static void main(String args[])
{
RMIMainApp app = new RMIMainApp();
app.execute();
// try
// {
// xgisRMIDisconnectionServerSend obj1 = new xgisRMIDisconnectionServerSend();
// xgisRMIDisconnectionServer stub1 = (xgisRMIDisconnectionServer) UnicastRemoteObject.exportObject(obj1, 0);
// String ip = InetAddress.getLocalHost().getHostAddress();
// // Bind the remote object's stub in the registry
// Registry registry = LocateRegistry.getRegistry(ip, 8846);
// registry.bind("xgisClient1", stub1);
//
// xgisRMIConnectionServerSend obj2 = new xgisRMIConnectionServerSend();
// xgisRMIConnectionServe stub2 = (xgisRMIConnectionServe) UnicastRemoteObject.exportObject(obj2, 0);
// registry.bind("xgisClient2", stub2);
//
// System.out.println("Server ready");
// }
// catch (Exception e)
// {
// System.err.println("Server exception: " + e.toString());
// e.printStackTrace();
// }
}
public void execute()
{
try
{
String ip = InetAddress.getLocalHost().getHostAddress();
Registry registry = LocateRegistry.getRegistry(ip, 8846);
xgisXPubRMIConnectionServerSend obj2 = new xgisXPubRMIConnectionServerSend(ip, 8849);
xgisXPubRMIConnectionServe stub2 = (xgisXPubRMIConnectionServe) UnicastRemoteObject.exportObject(obj2, 0);
registry.bind("xgisClient2", stub2);
System.out.println("Server ready");
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null, "RMI for XPub has not been registryed!", "RMI For XPub", 1);
System.exit(0);
}
}
}//////////////////////////////////////////
客户端方法体为:
/**
* 执行方法
* 进行登录的方法
*/
public void execute()
{
// Client cc = new Client(myApplication);
//获取公网IP
String ip = myApplication.getCenterAddress();
try
{
if(myApplication.getXPubRMI() == null)
{
stub2 = (xgisXPubRMIConnectionServe)Naming.lookup("//"+ip+":8846/xgisClient2");
myApplication.setXPubRMI(stub2);
myApplication.setXPubClientMode("online");
}
String info[] = login.getInfo();
System.out.println("登录事件");
xgisProperties xp = new xgisProperties();
xp.setProperty(XPubCommandConstants.XPUB_LOGIN, info);
xgisInformation xf = new xgisInformation( XPubCommandConstants.XPUB_LOGIN, xp); myApplication.sendToXPubAndExecuteResult(xf);
}
catch( Exception e)
{
e.printStackTrace();
} }///////////////////////////////////////
stub2 = (xgisXPubRMIConnectionServe)Naming.lookup("//"+ip+":8846/xgisClient2");
会抛出如下错误:java.rmi.ConnectException: Connection refused to host: 61.29.147.250; nested exception is:
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Unknown Source)
at XPub.tools.operations.usermanage.LoginOp.execute(LoginOp.java:67)
at teamax.tools.PlainTool.actionPerformed(PlainTool.java:108)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)
... 32 more
RMIMainApp app = new RMIMainApp();的前面
如果真是这样,好像RMI是透不过来的,我当时作rmi那个项目的时候,几乎试过了所有的方法,终以失败告终,如果你的数据量不太大的话,我建议你改成web service方式