|
|
Comments and Discussions
|
|
 |

|
how can I execute this program to sync my system whit internet time servers after execute?
should I change this program or use dll Import?
plz help me .I cant write & understand En good.
|
|
|
|
|

|
Hi
How can you implement a timeout into this?
If the IP is not a NTP server then the app hangs at NTPData = TimeSocket.Receive(EPhost) as there's no data to receive
cheers
|
|
|
|

|
You need to dispose the UdpSocket, or you'll leak.
//Connect the time server
using (UdpClient TimeSocket = new UdpClient())
{
TimeSocket.Connect(EPhost);
Otherwise... it's definitely cool!-bruce
|
|
|
|

|
I noticed there is no license specified for this code. Can you kindly provide license terms? Thanks.
|
|
|
|

|
For this useful article and source code,
thanks in advance...
|
|
|
|

|
if no ip by this address the program is stop to long. can you help?
|
|
|
|

|
Hi Valer,
what are the conditions to use your code in commercial environments ?
Harm Jonker
|
|
|
|

|
Has anyone experienced any problems getting the correct time if the device/computer if the querying computer is set wrongly in another daylight savings period?
i.e. if my computer clock is set to Jan 7th 2008 08:00, and i run the code on April 7th 08:00 - my clock will be set to April 7th 09:00 - one hour off. This does not happen if i run this in a date in the same daylight savings period.
Alex
|
|
|
|

|
The program block, when I compile in debug, it's at line :
NTPData = TimeSocket.Receive(ref EPhost);
because I recieve nothing from the serveur...
Someone have an idea ?
|
|
|
|

|
I think someone has already mentioned this, but to use this in Compact Framework, you'll need to change kernel32 to coredll.dll. Also, I found that Active Sync would block NTP. It took me a while to figure that problem out, so I hope it helps somebody else.
|
|
|
|

|
Really a great class 2 use.Good work buddy
btw how can i change the system time through code? bcoz as far as i know we can only read system time in c#
Vikas Salvi
Programmer Analyst
|
|
|
|

|
The SNTP C# code works on desktop PC. But while trying it on Pocket PC emulator am unable to receive any packets from the server.
Found that Active Sync does not support UDP.
Therefore, installed Virtual Machine Network Driver and VMWare. Yet the code does not work.
Please help me execute the code on Pocket PC. It is urgent.
rashmi chinchkar
|
|
|
|

|
This is a good article. I am developing a software that needs synchronization of time from server. But i dont see the way to get server time by using your class. Could you please tell me how?
I look forward to hearing from you.
Try
|
|
|
|

|
Hi All,
Can anybody provide me sample code in C++ for changing the client machine time from TIME SERVER?
This is very urgent..
Abhijit
|
|
|
|

|
Just wanted to say thanks for writing this. I think it will come in handy in my current project.
|
|
|
|

|
Firstly let me say that this is an excellent class an extremely useful.
That being said, I am encountering a small problem that hopefully somebody could shed some light on.
If I pass an IP address to the SNTPClient constructor it always returns succesful, even if the IP doesnt exist. As an example:
client = new SNTPClient("172.96.211.41"); client.Connect(true);
Console.Writeline(client.ToString());
Doesnt throw any exceptions and returns this
Leap Indicator: No warning
Version number: 3
Mode: Server
Stratum: Secondary Reference
Local time: 27/05/2005 16:29:39
Precision: 9.5367431640625E-07 s
Poll Interval: 1 s
Reference ID: skylar.fbamedia.co.uk (80.253.108.112)
Root Delay: 34.912109375 ms
Root Dispersion: 90.972900390625 ms
Round Trip Delay: 1 ms
Local Clock Offset: 0 ms
I have to admit, I have no idea where the reference ID is coming from.
If I use a non existant host name (e.g. foobar) it does throw an exception.
post.mode = postmodes.signature;
SELECT everything FROM everywhere WHERE something = something_else;
> 1 Row Returned
> 42
|
|
|
|

|
Hi!
Indeed a good article. Great job. I was searching for this functionality on net for quiet some time (to access a time server, as this is needed in my project).
I downloaded the source code and rebuilt it. But the app. is not running on my system. It throws an SocketException with Message : "No such Host is known" and Error code : 11001.
I tried to change the Time Server URL but with no succcess. The Exception is thrown while resolving the IP Address from URL in the line
IPHostEntry hostadd = Dns.Resolve(TimeServer);
of NTPClient.cs's Connect function.
Later I read about ur latest NTPClient app in the discussion board. But I'm facing the same problem.
I guess problem is that I'm using a proxy Server, and app is not able to bypass it. I tried to search ways to bypass the proxy server but again no success.
I would be really greatful to you if you could help me in solving this problem, as I need this functionality to access the Time Server to get the current time of any given location, for eg. London, France etc.
With Regards
and lots of thanks in advance
Shweta
|
|
|
|

|
This part of the code :
// Precision (in milliseconds)
public double Precision
{
get
{
return (1000 * Math.Pow(2, NTPData[3]));
}
}
is wrong; it assumes the precision given in the received data is an unsigned byte instead of a signed byte which leads to abnormal results.
// Precision (in milliseconds)
public double Precision
{
get
{
return (Math.Pow(2, (sbyte)NTPData[3]));
}
}
should work much better
|
|
|
|

|
I downloaded the source code and rebuilt it with .NET2003. It runs fine on my Win2000 machine but under WinXP Professional, I get the same exception "An existing connection was forcibly closed by the remote host" that somebody else mentioned. It's socket error code 10054 (WSACONNRESET) if that helps. Does anybody know what's going on?
|
|
|
|

|
This sample doesn't work when we retrieve the time from a W2K machine. If instead of the specified servers, any W2K machne is specified as the server, the application throws an exception "An existing connection was forcibly closed by the remote host". Is there any solution to this?
|
|
|
|

|
Good job at implementing this under C#.
One improvement to make it run under Windows CE would be to PInvoke the correct system dll that contains "SetLocalTime()". Under CE it is found in "coredll.dll" instead of "kernel32.dll".
Therefore there should be a conditional compile for either CE or the PC depending on the platform you are building for:
/*
you must add _WIN32_WCE to your "Conditional Compilation Constants"
in your project settings
*/
#if _WIN32_WCE
[DllImport("coredll.dll")]
static extern bool SetLocalTime(ref SYSTEMTIME time);
#else
[DllImport("kernel32.dll")]
static extern bool SetLocalTime(ref SYSTEMTIME time);
#endif
Thank you for this great class!
-Chris
Got RFID?
www.identecsolutions.com[^]
|
|
|
|

|
Incase, you are still looking for it.
The url for Java implementation of a NTP client by Michel Van den Bergh is http://alpha.luc.ac.be/Research/Algebra/Members/Java/
Cheers,
Kavitha Gopal
|
|
|
|

|
It would be nice if you could specify a timeout for the server connection. If it can't connect, the program seems to run indefinitely.
|
|
|
|

|
Some of your routines return a time span in milliseconds as a Double value. I'd use the standard TimeSpan instead.
Doing so is easy enough: a 'tick', the unit of time for TimeSpan, is 0.1µs, which makes 10 million ticks per second, compared to the 2^16 or 2^32 in the NTP packet.
Note that both the DateTime and TimeSpan types use an Int64 to store their value.
Jeffrey
Everything should be as simple as possible, but not simpler. -- Albert Einstein
http://www.extremeoptimization.com/
|
|
|
|

|
I have changed the client code so you can specify one or more NTP servers on the commandline
Below is the source. This way the demo client is of more use
namespace TimeSync
{
using System;
public class Synchronizer
{
public static int Main(string[] args)
{
Console.WriteLine("Time Synchronizer (C)2001 Valer BOCAN ");
Console.WriteLine("altered by Ramon Smits ");
Console.WriteLine("This program implements the Simple Network Time Protocol (see RFC 2030)\r\n");
if(args.Length==0) {
Console.WriteLine("\nSpecify one or more time servers on the commandline (DNS hostname or IP");
return -1;
}
NTPClient client;
foreach(string address in args) {
try {
Console.WriteLine("Connecting to: {0}\r\n", address);
client = new NTPClient(address);
client.Connect(true);
Console.Write(client.ToString());
return 0;
}
catch(Exception e) {
Console.WriteLine("ERROR: {0}", e.Message);
}
}
return -1;
}
}
}
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
Implementation of the Simple Network Time Protocol (RFC 2030) in C#
| Type | Article |
| Licence | CPOL |
| First Posted | 13 Mar 2001 |
| Views | 207,728 |
| Bookmarked | 87 times |
|
|