title: How would I choose in java that which port is free to use for ServerSocket or Socket?
body: <p>I'm working on java. How would I check that a port is free to use for a <code>ServerSocket</code>? 
  Moreover when a Socket is returned by the <code>accept()</code> function is it given a port and IP address by default or I would have to specify that too?</p>