简体   繁体   English

Java 应用程序可以连接到特定的 ip 和端口,但端口未在防火墙中打开

[英]Java application can connect to a specific ip and port but port isn't open in the firewall

The following java code listens for incoming connections on a specific port.以下 java 代码侦听特定端口上的传入连接。 I see that clients can connect but how is that possible if the server port is not open in the firewall?我看到客户端可以连接,但是如果服务器端口在防火墙中没有打开,那怎么可能呢?

ServerSocket serverSocket = new ServerSocket();
InetSocketAddress addr = new InetSocketAddress("localhost", 5555);
serverSocket.bind(addr);

Thank you.谢谢你。

I see that clients can connect我看到客户端可以连接

Only if those clients are in the same localhost, because your server port is bound to 127.0.0.1:5555, not 0.0.0.0:5555.仅当这些客户端在同一个本地主机中时,因为您的服务器端口绑定到 127.0.0.1:5555,而不是 0.0.0.0:5555。

but how is that possible if the server port is not open in the firewall?但是如果服务器端口没有在防火墙中打开,那怎么可能呢?

Because the firewall doesn't have anything to do with communications within the localhost.因为防火墙与本地主机内的通信没有任何关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM