 |
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi Alex
Yes I have just had the same problem. It turns out when the code is correcting the date/time for the different time zone it is using the current date/time of the querying computer. If the querying computer is in a different time zone then the offset can be out by 1 hour.
The problem can be solved by replacing the calls to GetUtcOffset() as below:
Replace: // Take care of the time zone TimeSpan offspan = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now); return time + offspan;
With: // Take care of the time zone TimeZone currentTimeZone = TimeZone.CurrentTimeZone; return currentTimeZone.ToLocalTime( time );
This now converts the UTC time to the local time without using the querying computers clock.
Regards Geoff
modified on Friday, June 6, 2008 12:18 AM
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
 |
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 ?
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
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.
|
| Sign In·View Thread·PermaLink | 1.69/5 (4 votes) |
|
|
|
 |
|
 |
The way that I handled this was to not have the device Active Sync'ed when I called NTP. This wasn't an issue for me because for this project, the devices were never Active Sync'ed after development. I supppose, and when I say suppose, I mean wild guess. If you really had to get around this, you could write an app that was both server and client with a normal port on the client side, and a variable port on the server side so you could find a port that was open. That would be a pretty big project. If the time doesn't need to be so exact, you could probably just do it over a web service.
I should also point out that in Compact Framework, the UDPClient has no timeout. I tried running this in a seperate thread, but we ended up just running NTP in a seperate exe so the main app didn't run out of threads.
Good luck.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I agree! This is really handy code. As old as this article is, it is still very useful and exactly what I was looking for. A big 5 from me. 
Vikas Salvi wrote: btw how can i change the system time through code?
It's right there in the code - the interop call to SetLocalTime()
QRZ? de WAØTTN
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
 |
That is pretty simple. Read the manual  You need to instantiate the NTPClient class, then "connect" to the server. After that, have a look at how the ToString() method is implemented. Everything is there.
Delta Forth .NET (www.dataman.ro)World's first Forth compiler for the .NET platform
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
 |
Yeah, you are right. But to get server time is to call the method ReceiveTimestamp? I notice that both server and local time are the same. Or any other way to get server time?
|
| Sign In·View Thread·PermaLink | 3.00/5 (1 vote) |
|
|
|
 |
|
 |
Sorry for misunderstanding. I can manage things right now. Thank alot for your nice class and your reply.
Try
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi All, Can anybody provide me sample code in C++ for changing the client machine time from TIME SERVER? This is very urgent..
Abhijit
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
 |
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"); //this ip doesnt exist and cannot be pinged or telnetted to port 123 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
|
| Sign In·View Thread·PermaLink | 2.00/5 (2 votes) |
|
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
 |
Ask the sysadmin to open the port 123 for your machine. The same happens in my office. If I connect to Internet from home, the program works ok.
Delta Forth .NET (www.dataman.ro) World's first Forth compiler for the .NET platform
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | 1.50/5 (2 votes) |
|
|
|
 |
|
 |
The issue was already addressed around September 2003, see the latest version at http://www.dataman.ro/sntp. Thanks for reminding me that I need to update the article on CP.
Delta Forth .NET (www.dataman.ro) World's first Forth compiler for the .NET platform
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |