RMI绑定到SAME端口但在SAME主机上有不同的IP地址 [英] RMI binding to SAME port but DIFFERENT IP address on SAME host

查看:78
本文介绍了RMI绑定到SAME端口但在SAME主机上有不同的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的计算机有3个虚拟IP地址(192.168.1。[5-7]),那么我可以如何启动同一个RMI应用程序的3个实例(每个实例都以
不同的属性/配置),每个都在端口1234上侦听,但每个

实例绑定到不同的IP地址。


是说:

实例#1绑定到192.168.1.5/port 1234

实例#2绑定到192.168.1.6/port 1234

实例#3绑定到192.168.1.7/port 1234


我想我正在寻找类似的东西:

注册表注册表= LocateRegistry.createRegistry(< IPADDR> ;,< PORT>);


我试过

System.setProperty(" java.rmi.server.hostname","< IP ADDR>");

但没有运气

当前代码看起来像这样:


/ **** ***服务器端********* /

System.getProperties()。setProperty(" java.rmi.serve r.hostname",serverip);

Re gistry registry = LocateRegistry.createRegistry(serverport);

registry.rebind(" RMITest",this);


// serverip是要绑定的IP到...服务器端口是端口1234

/ *******客户端********** /

Registry registry = LocateRegistry.getRegistry(serverip,serve rport);

RMITestInterface rmit =(RMITestInterface)(registry.lookup(" RMITest"));

rmit.dosomethingcool ();

第二个实例(即使serverip不同)抱怨

java.rmi.server.ExportException:端口已在使用中:1234;嵌套

异常是:java.net.BindException:地址已经在使用


这些必须是每个应用程序的单独实例

客户...我知道可以在不同的端口运行它们,

但是在大型集群环境中这是不可接受的。这个

会很快成为一个完整的噩梦。

我错过了什么?!?!我已经googled高低,看了我所有的java书籍,但没有提到这样的场景!任何人?


TIA!


-alex

If I have a machine with 3 virtual IP addresses (192.168.1.[5-7]), how
can I start 3 instances of the same RMI application (each started with
different properties/configs), each listening on the port 1234, but each
instance binds to a different ip address.

that is to say:
instance #1 binds to 192.168.1.5/port 1234
instance #2 binds to 192.168.1.6/port 1234
instance #3 binds to 192.168.1.7/port 1234

I guess I am looking for something like:
Registry registry = LocateRegistry.createRegistry(<IPADDR>,<PORT>);

I tried
System.setProperty("java.rmi.server.hostname","<IP ADDR>");
but had no luck
current code looks something like this:

/******* server side *********/
System.getProperties().setProperty("java.rmi.serve r.hostname",serverip);
Registry registry = LocateRegistry.createRegistry(serverport);
registry.rebind("RMITest", this);

//serverip is the IP to bind to... server port is port 1234

/******* client side **********/
Registry registry=LocateRegistry.getRegistry(serverip,serve rport);
RMITestInterface rmit=(RMITestInterface)(registry.lookup("RMITest") );
rmit.dosomethingcool();
second instance (even though serverip is different) complains
java.rmi.server.ExportException: Port already in use:1234; nested
exception is: java.net.BindException: Address already in use

These have to be seperate instances of the application for each
customer... I know that it is possible to run them on different ports,
but this is really not acceptable in a large clustered environment. this
would become a complete nightmare very quickly.
what am I missing?!?! I have googled high and low, and looked through
all my java books, but see no mention of such a scenario! anyone?

TIA!

-alex

推荐答案

Alexander N. Spitzer <人** @ spitzer.NOSPAMPLEASE.org>在留言中写道

新闻:mN **************** @ nwrdny03.gnilink.net ...

[snipped]
"Alexander N. Spitzer" <al**@spitzer.NOSPAMPLEASE.org> wrote in message
news:mN****************@nwrdny03.gnilink.net...
[snipped]
我想我正在寻找类似的东西:
注册表注册表= LocateRegistry.createRegistry(< IPADDR>,< PORT>);
I guess I am looking for something like:
Registry registry = LocateRegistry.createRegistry(<IPADDR>,<PORT>);



LocateRegistry中没有带此签名的方法。你可以使用这种形式的

方法创建一个绑定到特定IP地址的

注册表对象:


public static Registry createRegistry(int port,RMIClientSocketFactory csf,

RMIServerSocketFactory ssf)抛出RemoteException


你必须提供一个实现RMIServerSocketFactory的类

接口(RMIClientSocketFactory parm可以为null);这个类将

创建一个ServerSocket,你必须绑定到所需的IP地址。

这是一个例子:


import java.rmi.server。*;

import java.io. *;

import java.net。*;

public class AnchorSocketFactory扩展了RMISocketFactory实现

Serializable

{

private InetAddress ipInterface = null;

public AnchorSocketFactory(){}

public AnchorSocketFactory(InetAddress ipInterface)

{

this.ipInterface = ipInterface;

}

public ServerSocket createServerSocket(int port)

{

ServerSocket serverSocket = null;

try

{

serverSocket = new ServerSocket(port,50,ipInterface);

}

catch(例外e)

{

System.out.println(e);

}

return(serverSocket);

}

public Socket createSocket(String dummy,int抛出IOException

{

return(新套接字(ipInterface,port));

}

public boolean equals(Object that)

{

return(that!= null&& that.getClass()== this.getClass());

}

}


在你的代码中执行以下操作:


AnchorSocketFactory sf = new AnchorSocketFactory(< your InetAddress>);

LocateRegistry.createRegistry(port,null,sf);


HTH


Alex Molochnikov

格式塔公司
www.gestalt.com


" Alexander N. Spitzer" <人** @ spitzer.NOSPAMPLEASE.org>在消息新闻中写道:< mN **************** @ nwrdny03.gnilink.net> ...
"Alexander N. Spitzer" <al**@spitzer.NOSPAMPLEASE.org> wrote in message news:<mN****************@nwrdny03.gnilink.net>...
如果我有一台3虚拟机IP地址(192.168.1。[5-7]),我如何启动同一个RMI应用程序的3个实例(每个应用程序以不同的属性/配置启动),每个实例都在端口1234上监听,但每个
实例绑定到一个不同的IP地址。

也就是说:
实例#1绑定到192.168.1.5/port 1234
实例#2绑定到192.168.1.6/port 1234
实例#3绑定到192.168.1.7/port 1234

我想我正在寻找类似的东西:
Registry registry = LocateRegistry.createRegistry( < IPADDR>,< PORT>);

我试过了System.setProperty(" java.rmi.server.hostname","< IP ADDR>") ;
但没有运气

当前代码看起来像这样:

/ *******服务器端******** * /
System.getProperties()。setProperty(" java.rmi.serve r.hostname&q uot;,serverip);
注册表注册表= LocateRegistry.createRegistry(serverport);
registry.rebind(" RMITest",this);

// serverip是IP绑定到...服务器端口是端口1234
/ *******客户端********** /
注册表注册表= LocateRegistry.getRegistry (serverip,serve rport);
RMITestInterface rmit =(RMITestInterface)(registry.lookup(" RMITest"));
rmit.dosomethingcool();

second instance(即使serverip不同)抱怨
java.rmi.server.ExportException:端口已在使用中:1234;嵌套
异常是:java.net.BindException:地址已经在使用

这些必须是每个
客户的应用程序的单独实例...我知道它是可以在不同的端口上运行它们,但是在大型集群环境中这实际上是不可接受的。这很快就会成为一场彻头彻尾的噩梦。

我错过了什么?!?!我已经googled高低,看了我所有的java书籍,但没有提到这样的场景! TIA!

-alex
If I have a machine with 3 virtual IP addresses (192.168.1.[5-7]), how
can I start 3 instances of the same RMI application (each started with
different properties/configs), each listening on the port 1234, but each
instance binds to a different ip address.

that is to say:
instance #1 binds to 192.168.1.5/port 1234
instance #2 binds to 192.168.1.6/port 1234
instance #3 binds to 192.168.1.7/port 1234

I guess I am looking for something like:
Registry registry = LocateRegistry.createRegistry(<IPADDR>,<PORT>);

I tried
System.setProperty("java.rmi.server.hostname","<IP ADDR>");
but had no luck
current code looks something like this:

/******* server side *********/
System.getProperties().setProperty("java.rmi.serve r.hostname",serverip);
Registry registry = LocateRegistry.createRegistry(serverport);
registry.rebind("RMITest", this);

//serverip is the IP to bind to... server port is port 1234

/******* client side **********/
Registry registry=LocateRegistry.getRegistry(serverip,serve rport);
RMITestInterface rmit=(RMITestInterface)(registry.lookup("RMITest") );
rmit.dosomethingcool();
second instance (even though serverip is different) complains
java.rmi.server.ExportException: Port already in use:1234; nested
exception is: java.net.BindException: Address already in use

These have to be seperate instances of the application for each
customer... I know that it is possible to run them on different ports,
but this is really not acceptable in a large clustered environment. this
would become a complete nightmare very quickly.
what am I missing?!?! I have googled high and low, and looked through
all my java books, but see no mention of such a scenario! anyone?

TIA!

-alex



Alex,

$ b终端主机为每个活动的IP地址保留多个端口。

来自NIC卡的数据被传递到协议栈,并且来源

ip地址已被丢弃到达端口的时间。


您可以尝试在单个端口上侦听单个RMI服务器,将

数据传递给基于jvm的给定实例客户ID。


Sam90


Alex,

I doubt an end host keeps multiple ports for each active ip address.
Data from a nic card is passed up the protocol stack, and the source
ip address has been discarded by the time it reaches the port.

You might try a single RMI server listening on a single port, passing
data to a given instance of a jvm based on customer id.

Sam90


> Alex,

我怀疑终端主机为每个活动的ip地址保留多个端口。
来自nic卡的数据传递到协议栈,源
IP地址在到达端口时已被丢弃。

您可以尝试在单个端口上侦听单个RMI服务器,将
数据传递给基于jvm的给定实例客户ID。

Sam90

I doubt an end host keeps multiple ports for each active ip address.
Data from a nic card is passed up the protocol stack, and the source
ip address has been discarded by the time it reaches the port.

You might try a single RMI server listening on a single port, passing
data to a given instance of a jvm based on customer id.

Sam90




Sam,在ASP环境中,需要单独使用

每个客户的实例。


Alex Molochnikov给了我正在寻找的答案,这是:


LocateRegistry中没有方法这个签名。你可以使用这种形式的

方法创建

a注册表对象绑定到特定的IP地址:

public static Registry createRegistry (int port,RMIClientSocketFactory

csf,RMIServerSocketFactory ssf)抛出RemoteException


谢谢Alex M.等人!



Sam, in an ASP environment, it is a requirement to have seperate
instances for each client.

Alex Molochnikov gave me the answer I was looking for, which was:

There is no method in LocateRegistry with this signature. You can create
a Registry object bound to a specific IP address using this form of the
method:

public static Registry createRegistry(int port, RMIClientSocketFactory
csf,RMIServerSocketFactory ssf) throws RemoteException

Thanks Alex M. et al.!


这篇关于RMI绑定到SAME端口但在SAME主机上有不同的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆