title: How to query date at time.windows.com NTP server by using C#.NET code?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1193955/how-to-query-an-ntp-server-from-c-sharp">How to Query an NTP Server from C#</a>  </p>
  </blockquote>
  
  
  
  <p>I'm trying get the datetime from <code>time.windows.com</code> NTP server, I'm using the following code:</p>
  
  <pre><code>using System;
  using System.IO;
  using System.Net.Sockets;
  
  namespace ntpdate2
  {
      class MainClass
      {
          public static void Main (string[] args)
          {
              var client = new TcpClient("time.windows.com", 123);
              client.SendTimeout = 60;
              using (var streamReader = new StreamReader(client.GetStream()))
              {
                  var response = streamReader.ReadToEnd();
                  Console.WriteLine(response);
                  streamReader.Close();
              }
  
  
  
          }
      }
  }
  </code></pre>
  
  <p>But it gives an: </p>
  
  <pre><code>Unhandled Exception: System.Net.Sockets.SocketException: Connection timed out
    at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remote_end) [0x00000] 
    at System.Net.Sockets.TcpClient.Connect (System.Net.IPEndPoint remote_end_point) [0x00000] 
    at System.Net.Sockets.TcpClient.Connect (System.Net.IPAddress[] ipAddresses, Int32 port) [0x00000] 
  The application was terminated by a signal: SIGHUP
  </code></pre>
  
  <p>How to fix this? thanks in advance.</p>