Avoid Windows Firewall popup with sockets on localhost

前端 未结 1 717
渐次进展
渐次进展 2021-02-07 19:23

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, listen

1条回答
  •  南方客
    南方客 (楼主)
    2021-02-07 19:42

    Use the three parameter constructor of the ServerSocket class to specify the IP address as well that the server it 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 Stack Overflow question, for more details.

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

    0 讨论(0)
提交回复
热议问题