java为什么我尝试运行客户端。另一台计算机上的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
# 1 楼答案
我自己解决了我的问题
我终于找到了我的java。防火墙上的exe被阻止
这就是为什么防火墙打开时我无法接收另一个请求的原因
并确保防火墙上的两个端口都必须打开