Search code examples
javasocketstcpnetwork-programmingserversocket

Where does server socket bind to?


In which IP this new ServerSocket(port); bind?
To all public IPs and localhost? Not sure about this.
If I have multiple interfaces does it bind to all?


Solution

  • This call is the equivalent of

    new ServerSocket(port, 0, null);
    

    According to the javadoc for this method:

    If bindAddr is null, it will default accepting connections on any/all local addresses.

    So yes, it will be bound to all interfaces.