title: Do client and server need to use same port to connect?
body: <p>I have a Server-Client program using java, I tried to create a <code>ServerSocket</code> with a port and Client <code>Socket</code> with different port and they cannot connect to each other. Client throw <code>ConnectException</code>. When I change the socket on Client to the same as the one I use for ServerSocket, they worked.</p>
  
  <p>As I understand from the aswer from this thread <a href="https://stackoverflow.com/questions/12715321/java-networking-explain-inputstream-and-outputstream-in-socket">Java Networking: Explain InputStream and OutputStream in Socket</a> if a machine create a socket with a port then that socket is bind to that machine, so why do client and server need to use same port to connect to each other?</p>
  
  <p>Also, two application can't use same port on a machine so what happen when two difference Server having same port and a machine need to connect to both of them through 2 different application?</p>