[英]How to bind socket to IP with java?
I have a JAVA application which runs on Linux. 我有一个在Linux上运行的JAVA应用程序。 I open a socket that binds to all IP. 我打开一个绑定到所有IP的套接字。 In production this is not acceptable. 在生产中这是不可接受的。
$ netstat -ano | grep 104
tcp 0 0 0.0.0.0:104 0.0.0.0:* LISTEN off (0.00/0/0)
I which to do this: 我要这样做:
$ netstat -ano | grep 104
tcp 0 viewer1.com:104 0.0.0.0:* LISTEN off (0.00/0/0)
Is this something I can change in my Linux box (red hat) or is it application specific. 这是我可以在Linux机器(红色帽子)中更改的东西,还是特定于应用程序的。 ie I have to modify my code? 即我必须修改我的代码?
Most likely, you'll need to modify the Java application to specify a bind address. 最可能的是,您需要修改Java应用程序以指定绑定地址。
The most commonly used API for server socket construction binds to all address by default. 默认情况下, 用于服务器套接字构建的最常用API绑定到所有地址。 However, there is another that can bind to a specific address. 但是, 还有另一个可以绑定到特定地址。 There's a small chance that the application is already using the latter constructor, and it's just not configured with a value. 该应用程序已经在使用后者的构造函数的可能性很小,并且只是未使用值进行配置。 If that's the case, you just need to find out how to configure an address. 在这种情况下,您只需要了解如何配置地址即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.