title: Find server listening on a specific port on local network
body: <p>I have a server application. I also have a client application. I am able to establish a tcp connection between the applications when both applications happen to be on the same network. so let's say that the computer running the server application is listening from new connections on port 2121 and it has the LAN ip address 192.168.0.120.  On a different computer running the client application I will be able to establish a connection by providing port number 2121 and ip address 192.168.0.120. </p>
  
  <p>Is there a way to find all computers on a network that are listening on port 2121? </p>
  
  <p>One algorithm that I am thinking now is like:</p>
  
  <ul>
  <li><p>get ip address of current computer and lets say it comes out as 192.168.0.145.</p></li>
  <li><p>now most likely the server will be listening on ip addresss 192.168.0.?  </p></li>
  <li><p>then ping 192.168.0.1 on port 2121 then 192.168.0.2 on port 2121 ... and then keep going. </p></li>
  </ul>
  
  <p>I don't know if that method is efficient. moreover there might be a possibility that the server happens to be listening on ip address 192.168.1.x  </p>
  
  <p>So what changes will I have to make to my server and client application so that the client is able to  find all the servers listening on port 2121?</p>