开发者

Java Socket Accept Connection from one IP

开发者 https://www.devze.com 2023-02-04 19:12 出处:网络
How to create a server socket which accept connection from a specific ip 开发者_如何学编程address?new ServerSocket(1234, 50, InetAddress.getByName(\"1.2.3.4\"));

How to create a server socket which accept connection from a specific ip 开发者_如何学编程address?


new ServerSocket(1234, 50, InetAddress.getByName("1.2.3.4"));

Where 1234 - port 1.2.3.4 - the IP to listen to. So, if you have 2 IP addresses on 1 machine (1.2.3.4 and 1.2.3.5) the code above will subscribe to the first IP only.


Here is an example http://www.exampledepot.com/egs/java.nio/NbServerSocket.html

0

精彩评论

暂无评论...
验证码 换一张
取 消