简体   繁体   English

主机上的 ServerSocket.accept() 不接受源自来宾 VM 的连接

[英]ServerSocket.accept() on host does not accept connection originating in guest VM

In my Java app, I have the following code:在我的 Java 应用程序中,我有以下代码:

_serverSocket = new ServerSocket();
_serverSocket.setReuseAddress(true);
_serverSocket.bind(new InetSocketAddress(port));
// _serverSocket = ServerSocket[addr=0.0.0.0/0.0.0.0,localport=33202]
_socket = _serverSocket.accept();
...

In a VM, I launch a (black box) client application that tries to connect to the above server.在 VM 中,我启动了一个(黑匣子)客户端应用程序,尝试连接到上述服务器。 For an unknown reason, no connection is established and accept never returns.由于未知原因,没有建立连接并且接受永远不会返回。

I know the client app is trying to connect, as I see appropriate packets in Wireshark:我知道客户端应用程序正在尝试连接,因为我在 Wireshark 中看到了适当的数据包: Wireshark 屏幕截图

I can't launch the same client application on my host machine but I can successfully establish a TCP connection from the host with nc , so I know the server is actually listening.我无法在主机上启动相同的客户端应用程序,但我可以使用nc从主机成功建立 TCP 连接,所以我知道服务器实际上正在侦听。 The VM and host are in the 10.11.1.0 subnet. VM 和主机位于 10.11.1.0 子网中。 The host has IP 10.11.1.1, the VM 10.11.1.68.主机的 IP 为 10.11.1.1,VM 为 10.11.1.68。 They can ping each other.他们可以互相ping通。

But still, for some reason, the TCP packets do not seem to arrive at my Java code.但是,出于某种原因,TCP 数据包似乎没有到达我的 Java 代码。 Any ideas why or how I could further debug this?任何想法为什么或如何进一步调试?

I could solve my problem.我可以解决我的问题。 It was indeed a problem with the host's Windows Firewall settings.确实是主机的Windows防火墙设置有问题。 After adding an inbound rule for javaw.exe of the specific JDK I was using to run the server, the connection could be established successfully.为我用来运行服务器的特定 JDK 的javaw.exe添加入站规则后,可以成功建立连接。

Shout out to Corporate IT that didn't just let me disable the firewall quickly to determine if that was the cause of the problem.向公司 IT 大喊大叫,他们不仅让我快速禁用防火墙以确定这是否是问题的原因。 :\\ :\\

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

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