Possible Duplicate:
How to Query an NTP Server from C#
I'm trying get the datetime from time.windows.com
NTP server, I'm using the following 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();
}
}
}
}
But it gives an:
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
How to fix this? thanks in advance.