title: Java TCP socket: java.net.ConnectException: connect: Address is invalid on local machine, or port is not valid on remote machine
body: <p>I am creating socket using <code>socket = new Socket(host, port, InetAddress.getLocalHost(), clientPort);</code>. I want the socket to listen to particular port at client side. But when I use <code>InetAddress.getLocalHost()</code> I get <code>java.net.ConnectException: connect: Address is invalid on local machine, or port is not valid on remote machine</code>.</p>
  
  <p>But when I use <code>InetAddress.getByName("localhost")</code> it works fine. But I require IP address of the machine in server side. So when I use <code>socket.getInetAddress()</code> I want ipadress and not 127.0.0.1.</p>
  
  <p>Can anyone please help.
  I am using eclipse. Can this be a firewall issue?</p>
  
  <p>Thanks</p>