避免使用localhost上的套接字弹出Windows防火墙 [英] Avoid Windows Firewall popup with Sockets on localhost

查看:350
本文介绍了避免使用localhost上的套接字弹出Windows防火墙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个简单的Java应用程序,它使用套接字与自身的多个实例进行交互。第一个实例自动承担服务器的角色,侦听特定端口,并且所有后续实例都连接到它。

I have written a simple Java application that interacts with multiple instances of itself using sockets. The first instance automatically takes on the role of the server, listening on a specific port, and all subsequent instances connect to it.

我面临的问题是Windows防火墙弹出询问我是否要取消阻止该程序接受传入的网络连接。问题是:如果你让应用程序被阻止并不重要,因为应用程序的实例总是在同一台机器上,所以它总能工作。

The problem I'm faced with is that Windows Firewall pops up asking me if I want to unblock the program from "accepting incoming network connections". The thing is: it doesn't matter if you leave the application blocked, because the instances of the application are always on the same machine, so it will always work.

我的问题是:我能否以某种方式告知Windows我甚至不想接受传入的网络连接?

My question is: can I inform Windows somehow that I don't even want incoming network connections to be accepted?

推荐答案

使用 ServerSocket类的三个参数构造函数,用于指定服务器应该监听的IP地址。这样,您可以将服务器限制为仅在127.0.0.1上侦听,而不像默认值0.0.0.0。有关详细信息,请参阅此相关SO问题

Use the three parameter constructor of the ServerSocket class to specify the IP address as well that the server should listen on. That way you can restrict the server to listen only on 127.0.0.1, unlike the default of 0.0.0.0. See this related SO question, for more details.

编辑:最好使用InetAddress.getByName(null)来获取本地地址。

EDIT: It is preferable to use InetAddress.getByName(null) to obtain the local address.

这篇关于避免使用localhost上的套接字弹出Windows防火墙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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