title: Check if IP Address and Port are responding
body: <p>I'm currently developing a autodiscover feature for SNMP printer monitor software. I need a helper method, which is executed from several threads each checking an ip in a range, to determine if a device at a certain ip address, is responding to port 9100, to establish that it in fact is a printer, before sending an SNMP request to it.</p>
  
  <p>I've ended up with the following method, however im unaware if this is the correct approach, and if it by convention is correct use of the Close() method in this context (I can see that Dispose(), Disconnect() and Shutdown() methods are also available, so which to use?). Furthermore i need to set a timeout value of max. 5 seconds, so the threads won't linger for too long, before presenting a result. My code so far:</p>
  
  <pre><code>private bool GetTCPPrinterResponse(IPAddress _ip)
  {
          int port = 9100;
  
          bool isResponsive = false;
  
          Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  
          try
          {
              s.Connect(_ip, port);
  
              isResponsive = true;
          }
          catch (SocketException)
          {
              isResponsive = false;
          }
          finally
          {
              s.Close();
          }
  
          return isResponsive;
      }
  </code></pre>
  
  <p>After method edit:</p>
  
  <pre><code>private bool GetTCPPrinterResponse(IPAddress _ip)
          {
              int port = 9100;
  
              bool isResponsive = false;
  
              using (Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
              {
                  s.ReceiveTimeout = 3000;
                  s.SendTimeout = 3000;
  
                  try
                  {
                      s.Connect(_ip, port);
  
                      isResponsive = true;
                  }
                  catch (SocketException)
                  {
                      isResponsive = false;
                  }
              }
  
              return isResponsive;
          }
  </code></pre>
  
  <p>Setting of Timeout properties, has no effect.</p>