ehsun7b
ehsun7b

Reputation: 4866

Java Socket Accept Connection from one IP

How to create a server socket which accept connection from a specific ip address?

Upvotes: 2

Views: 1394

Answers (2)

AlexR
AlexR

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

Navi
Navi

Reputation: 8756

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

Upvotes: 1

Related Questions