DEVBUZZ Homepage Using NTP to set the time on your Pocket PC
 
Web www.devbuzz.com
  HOME PAGE
  All Articles
  Advertise
  Consulting

 Development
  Discuss - Forums
  Still in the box?
  .Compact Framework
  Code Snippets
  SQL Server CE
  Database
  MS Resources
 Stores
  Developer Controls
  Pocket PC Hardware
  Pocket PC Software
  Pocket PC Books
  .NET CF Books
  Book Reviews
  SPB SW Discounts
  RESCO SW Discounts
 DEVBUZZ Info
  About Us
  Help
  Join our email list
  Links & Ratings
  Press & Comments
  Pocket PC version
  Software Reviews
  Hardware Reviews
 Authors
  Authors
  Article Guide
  Competitions
 Resources
  Developers
  Register
  Login

  SPB Discounts!
 Columnists
  Rick Winscot
 Past Blast
  Personal Media Ctr
  Gizmobility
  eVB Legacy
  Old news
  Hosted Software
  Wireless
  Newsletters
  Carl Davis
  Upton Au

 Pocket PC Registry
  Join the registry
  View current list
 Current Poll
Are you converting to .NET Compact Framework?
Yes, it has changed my life!
No, I'm sticking with eVB
.NET CF what's that`?

Current results
3431 votes so far
 Recent Forum Threads [goto forums]

Get Computername
read... (67 hits)


Great aid to development productivity
read... (82 hits)


ThreadingTimer sample code
read... (143 hits)


Multithreading with .NET CF
read... (194 hits)


Moving from eMbedded Visual Basic to Visual Basic .NET
read... (166 hits)


.NET Compact Framework 2.0 Service Pack 2
read... (226 hits)


Transfer Data from SQL Server 2000 to SQL Server Compact Edition
read... (298 hits)


This protocol version is not supported
read... (236 hits)


Converting Lowercase to uppercase wont work
read... (203 hits)


Direct access to MS SQL Server 2000
read... (374 hits)


Creating SDF file in Desktop
read... (513 hits)


Winsock in CF.NET
read... (316 hits)


Using Pocket Outlook to submit HTML page form with MAILTO action
read... (420 hits)


Missing file "System.Data.PocketPC.asmmeta.dll"
read... (268 hits)


HP iPAQ hw6915 Serial Port Issue
read... (309 hits)


Info on the recent forum changes
read... (341 hits)


SqlServer tools from Redgate
read... (383 hits)


Arrow keys and Hardware navigation button
read... (393 hits)


O2 XDA lls pin sync cable to comport
read... (322 hits)


Creating dynamic folders on Pocket PC OS
read... (299 hits)

Custom Windows Mobile software development.
LBS Challenge 2007
LBS Challenge Eight previous NAVTEQ Global LBS Challenge® participants have received venture capital funding and nine past LBS Challenge winners have launched commercial applications on major wireless carriers. Register your non-commercial LBS application in the 2007 NAVTEQ Global LBS Challenge in one of three regions: Americas, Europe-Middle East-Africa (EMEA) or Asia-Pacific(APAC). You could win a share of $2 million in prizes. This could be your year.
Dream. Develop. Win.

Development | Starting Out

Using NTP to set the time on your Pocket PC
Written by Pete Vickers  [author's bio]  [read 52667 times]
Edited by Derek

Download the code   Discuss this article   eVB Ver 3.0   

Page 1  Page 2  Page 3 

I was talking to someone who needed the correct time on their Pocket PC for deliveries etc and needed to access a time server. There are many 'time servers' that can be accessed on the internet which will give you the correct time using NTP (Network Time Protocol). Quite difficult to do in VB6, never mind eVB, but undaunted, we will continue. If you take a look at the services file on your PC (c:\winnt\system32\drivers\etc\services), you will see an entry:-

time 37/tcp timserver

This tells us we can get to the timeserver by using port 37. Try to 'Telnet' in to port 37 on your PC (alternatively try "telnet pogostick.net 13"). Chances are the connection will be refused. Not so undaunted now. End of article - it doesn't work. But hang on, if we take a closer look at the services file, we find at number 13 in the charts...

daytime 13/tcp

Just try 'Telnet' to port 13 on your PC. You will get disconnected fairly smartly, but this time, you will get something back from your PC. What you will get back is a time and date. Not in a useable format, but what's life without a challenge.

So, lets get down to cutting some code. Fire up eVB, and scatter randomly on the form, 2 command buttons, 1 label, a combo box, a listbox and just for good measure, add a winsock control as you may need it later. Don't worry about the positioning, we can always do it in code. Don't worry about the names, leave them as default. Hell, we're programming, naming standard are for wimps.

You should now have a form that looks somewhat like this...

The command buttons are going to allow us to connect and disconnect. The combo box will list our time servers, and the listbox will give us an indication of what is happening behind the scenes.

Next, declare some form variables and API calls.

Option Explicit
Private sysTime As String
Private iyear As Integer
Private imonth As Integer
Private idow As Integer
Private iday As Integer
Private ihour As Integer
Private imin As Integer
Private isec As Integer
Private imill As Integer
Private Rbuff As String
Private bConnected As Boolean
Private lret As Long
Const IDC_WAIT = 32514
Declare Function SetLocalTime Lib "Coredll" _
(ByVal lpSystemTime As String) As Long
Declare Function LoadCursor Lib "Coredll" _
Alias "LoadCursorW" _
(ByVal hInstance As Long, _
ByVal lpCursorName As Long) As Long
Declare Function SetCursor Lib "Coredll" _
(ByVal hCursor As Long) As Long

Next the form_load procedure

Private Sub Form_Load()
Command1.Move 120, 120, 1335, 495
Command2.Move 120, 720, 1335, 495
Label1.Move 1560, 120, 1695, 255
Combo1.Move 120, 1700, 3000, 300
list1.Move 120, 2200, 3000, 1000
Command1.Caption = "Connect"
Command2.Caption = "Close Winsock"
Command2.Enabled = False
Label1.Caption = ""
Combo1.AddItem "192.192.192.46" 'your server
Combo1.AddItem "ntp.ise.canberra.edu.au"
...
Combo1.listindex = 0

We are adding lots of servers to the combo box, but they are all contained in the sample code so we won't add them all now.

Next Page 

Back to Starting Out | [Article Index]

 

Back to the top of the page.
Franson GPS tools for the Pocket PC Chris De Herrera's Windows CE Website Windows CE News & Information Source RESCO Software discounts
Copyright ©2000-2008 by DEVBUZZ.COM, Inc., TX. USA.