Comments (4)
It's a really good question. There's a trade-off between how long to wait and desired accuracy. NTP was not designed to give accurate time quickly, it was designed to run 'forever' (on a Mac it gets started when you boot the computer, and it runs till you shut down), and to adjust the system clock occasionally, as required. In fact, NTP runs in the same way in iOS (maybe from about iOS 6 onwards, I don't when it was added to iOS). But iOS is a challenging environment for NTP .. phones don't maintain a continuous connection, and people can turn off NTP to set whatever time they want.
I wrote ios-ntp a long time time ago when the iOS system clock could be as much as 2 minutes off. After I made it available on GitHub, I realized it was being used to check for people 'cheating' expiry dates in games etc.
For the former use, keeping accurate to within a second, with no concern for cheating, I don't use ios-ntp any more; the system clock in modern iOS is good enough. For the latter use, checking the reported system time hasn't been tampered with, for example, something much simpler than NTP will do the job. Simpler code is embedded in ios-ntp (the complicated NTP algorithms use simpler methods to get the time samples they use) and I want to liberate it.
I've been meaning to just finish that simple piece of work for some time .. maybe you pushed me over the edge!!
from ios-ntp.
Thanks for your reply. I've been playing around with the "Instant Time Check". That is, I'm sending all hosts through it at once, collecting the replies, removing the offsets that fall outside of 1 standard deviation from the average, then taking the average of those that remain. Seems to work fairly well.
Two notes:
-
None of the netAssociations received using this method are "trusty". Is that expected?
-
I kept getting the following error after about the 6th or 7th time I clicked the "Instant Time Check" button: "Must bind socket before you can receive data." I don't believe that is really the problem, as the GCDAsyncUdpSocket documentation says binding is optional. I think the actual problem is that the socket isn't closed after receiving data. I added "[sock close]" inside the didReceiveData delegate method and I stopped getting the error.
from ios-ntp.
I really have to get back to this! I'm feeling guilty!!
-
I think "trusty" is an attribute gained after averages have been stable enough for confidence.
-
There have been some bugs in the GCDAsyncUdpSocket code fixed. Don't know if this is related, but I will put the latest version in on the next commit.
from ios-ntp.
Thanks! I ultimately decided to start the network clock when my app opens and set a timer to go off after 12 (arbitrary) seconds to save the offset and stop the clock.
As long as you're working on it, I think it would be cool to have it work find of like iOS location services, where it periodically calls a delegate with new time info and a "confidence" factor.
from ios-ntp.
Related Issues (20)
- iOS-ntp returning same value as device HOT 4
- Question for one-time check HOT 4
- Watching possible issue in CocoaAsyncSocket code
- Cocoa Pods released version HOT 1
- Hardcoded NTP Pool names HOT 13
- import error HOT 1
- EXC_BAD_ACCESS HOT 6
- What is missing from RFC 5905 HOT 2
- Grabbing ntpClientRecvTime Twice HOT 1
- Ability to Change the Time Servers Without Reboot
- Account for Packet Loss in One-Off Mode HOT 1
- Any update for cocoapod, version is still 1.1.1 HOT 2
- v1.1.7 updates coming soon .. HOT 1
- when not network to network, error: " dnssd_clientstub deliver_request ERROR:"
- Does not compile because of lacking GCDAsyncUpdSocket HOT 3
- 该网络时间从哪来?
- 有啥用呢? HOT 1
- How to get the accurate network time after modifying the system time HOT 13
- demo clock is wrong HOT 5
- Whether the poll interval can be automatically increase?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ios-ntp.