在 RMI 期间知道端口号 [英] knowing the port number during RMI

查看:71
本文介绍了在 RMI 期间知道端口号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 RMI 期间知道客户端和服务器的端口号?

Is there a method to know the port number of both the client and server during RMI?

当在 RMI 过程中将结果返回给客户端时,下次客户端请求该结果时,客户端和服务器之间的会话是否会在与上一次相同的端口上,从第一个结果返回以来服务器一直在运行还是创建了一个新端口?

When a result is returned during RMI to the client, next time the client requests the result, will the conversation between client and server be at the same port as the previous, when the server has been running since the first result was returned or a new port is created?

例如:

// call to a remote method add
     addServerIntf.add(d1,d2)
// after this call i get the added result

<小时>

// again call the add method by again starting the client
    addServerIntf.add(d1,d2)
// I get the result back as usual

在两次不同的调用中,客户端和服务器的端口号是否保持不变?

In the 2 different calls does the port number of client and server remain the same ?

我的客户端程序在输入类似 java AddClient localhost 100 200 这样的命令后退出,服务器上的方法返回300,客户端退出.下次我再次使用 java AddClient localhost 19 100 启动我的客户端.现在请求将从之前发送的相同端口发送,服务器会在同一端口接收请求吗?或者情况和我刚才写的不一样?

My client program exits after entering a command like java AddClient localhost 100 200 The method on the server returns 300 and the client exits. Next time i start my client again with java AddClient localhost 19 100. Now will request be sent from the same port as sent from before and will the server receive the request on the same port ? Or the situation is different from what i just wrote ?

推荐答案

有没有办法同时知道客户端和服务器的端口号?

Is there a method to know the port number of both the client and server?

没有.您无法提前知道客户端端口号,因为它是在连接时动态分配的,并且服务器 IP:port 嵌入在您无法获得的存根中.为什么你需要知道?这些信息对你没有多大好处:你不能使用它.

No. You can't know the client port number in advance, as it is allocated dynamically on connection, and the server IP:port is embedded in the stub where you can't get at it. Why would you need to know? The information can't do you much good: you can't use it.

当在 RMI 过程中将结果返回给客户端时,下次客户端请求结果,客户端和服务器在与以前相同的端口,当服务器已经自从返回第一个结果或创建新端口后运行?

When a result is returned during RMI to the client, next time the client requests the result, will the conversation between client and server be at the same port as the previous, when the server has been running since the first result was returned or a new port is created?

要么:

  • 使用相同的端口号重复使用客户端连接,或
  • 在客户端创建了一个可能带有新本地端口的新连接.

无法分辨是哪一个.服务器端口保持固定.

It is impossible to tell which. The server port remains fixed.

在 2 个不同的调用中,客户端和服务器的端口号保持不变?

In the 2 different calls does the port number of client and server remain the same ?

见上文.

我的客户端程序在输入类似 java AddClient localhost 100 200 的命令后退出.服务器上的方法返回 300,客户端退出.下次我用 java AddClient localhost 19 100 再次启动我的客户端.现在请求将从与之前发送的相同端口发送

My client program exits after entering a command like java AddClient localhost 100 200. The method on the server returns 300 and the client exits. Next time i start my client again with java AddClient localhost 19 100. Now will request be sent from the same port as sent from before

可能不会.

服务器会在同一个端口上收到请求吗?

and will the server receive the request on the same port?

如果没有看到您的服务器代码,就不可能说出来.如果在恒定端口上导出它,则在恒定端口上导出.如果没有,就没有.真的是同义反复.

Impossible to say without seeing your server code. If you exported it on a constant port, it is exported on a constant port. If not, not. Tautology really.

或者情况和我刚刚写的不一样?

Or the situation is different from what i just wrote?

我不明白这个问题.

这篇关于在 RMI 期间知道端口号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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