Reputation: 4866
How to create a server socket which accept connection from a specific ip address?
Upvotes: 2
Views: 1394
Reputation: 115388
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.
Upvotes: 4
Reputation: 8756
Here is an example http://www.exampledepot.com/egs/java.nio/NbServerSocket.html
Upvotes: 1