My machine has more than one IP address. How can I specify which address to use for a socket connection?

Tim Rohaly

Both Socket and ServerSocket have a constructor which allows you to specify a particular local IP address to use. In the case of Socket, there are two constructors:

    public Socket(InetAddress address, int port, InetAddress localAddr, int localPort)
    public Socket(String host, int port, InetAddress localAddr, int localPort)
In the case of ServerSocket, the constructor is:
    public ServerSocket(int port, int backlog, InetAddress localAddr)
All three of these constructors may throw an IOException.
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact