java - 为什么我尝试在另一台计算机上运行 Client.jar 但收到连接被拒绝”或“连接超时
问题描述
我花了一天多的时间,但仍然无法弄清楚我该如何解决这个问题。每次我关闭服务器上的防火墙时,我的另一台计算机都可以成功运行Client.jar。
我检查了我的服务器 PC 上的防火墙。我确定我打开了“4888”和“6151”端口,但仍然无法正常运行。
我不知道“W.getSocketFactory()”是如何工作的。
System.out.println("創造"+ W.getSocketFactory()); → 創造 null (Is it an issue?)
我的代码有问题吗?
下面是我的服务器代码:
public class RemoteServer extends UnicastRemoteObject implements MyRemote{
public static void main(String[] args)
{
try {
RMILocalSocketFactory W = new RMILocalSocketFactory(6151);
System.out.println("創造"+ W.getSocketFactory());
RMISocketFactory.setSocketFactory(W);
LocateRegistry.createRegistry(4888);
System.setProperty("java.rmi.server.hostname","175.183.49.139");
MyRemote Server = new RemoteServer();
Naming.rebind("rmi://175.183.49.139:4888/Remote_Hello!", Server);
} catch (Exception e) {
e.printStackTrace();
}
}
RemoteServer() throws RemoteException {}
public String SayHello()
{
System.out.println("RMI Connection");
return "you Connected Server\n" + "Server says , Hey!";
}
}
class RMILocalSocketFactory extends RMISocketFactory {
private int dataPort;
public RMILocalSocketFactory(int dataPort1){
this.dataPort = dataPort1;
}
public Socket createSocket(String host, int port) throws IOException {
String a = "175.183.49.139";
Socket check = new Socket(a = host, port);
return check;
}
public ServerSocket createServerSocket(int port) throws IOException {
return new ServerSocket(port);
}
}
(客户端)代码的一部分:
try {
LocateRegistry.getRegistry(4888);
MyRemote Service = (MyRemote)Naming.lookup("rmi://175.183.49.139:4888/Remote_Hello!");
String Say= Service.SayHello();
Area.append(Say);
} catch (Exception e) {
e.printStackTrace();
}
```[Problem Picture:][1]
[1]: https://i.stack.imgur.com/LkK5T.jpg
解决方案
我自己解决了我的问题。
我终于发现我在防火墙上的 java.exe 被阻止了。
这就是为什么在防火墙打开时我无法收到另一个请求的原因。
并确保两个端口也必须在防火墙上打开。
推荐阅读
- c# - 多维数组作为方法的参数
- javascript - Javascript 添加空格和额外的字母
- javascript - D3.js v5 模块化集群(可变半径?)
- ios - 领域。更新多个 ViewController 中的数据
- centos7 - 使用 Samba 配置 CTDB GlusterFS 的问题
- bash - 如何将命令“which”的输出存储在 bash 脚本的变量中?
- facebook - 有什么方法可以检测到用户点击了我在 Facebook、Messenger 上分享的链接?
- asp.net - WebMarkupMin.AspNet4.WebForms 缩小整个 aspx 文件
- ubuntu - awk 转义单引号
- flutter - 我正在尝试制作一个简单的应用程序来随机改变身体背景的颜色,但我在模拟器上得到的只是一个空白