Java Socket Accept Connection from one IP
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
精彩评论