Reading Computer's clock over a network

Posted on 1999-12-11
Medium Priority
Last Modified: 2013-11-13
How can I read other computer's clock over a network using VB code.

Are there any programs out there (VB or other) which will do this. I don't care about synchronizign the clocks on computers over a network but I want to know how to read other computer's clock over a network.

Thank you.
Question by:aussie_guy_nik
  • 5
  • 3

Author Comment

ID: 2274847
No comment
LVL 14

Accepted Solution

mcrider earned 800 total points
ID: 2274864
If you have a system that runs the DAYTIME protocol, you can use the winsock control to connect to that system on port 13.  Most UNIX systems run this service.

Once you connect, the system will send the time, then disconnect.  The format usually is one of the following:

     Sunday, December 12, 1999 23:59:10-EST
     SUN DEC 12 23:59:10 1999
     12 FEB 99 23:59:10 EST

See the following Microsoft Article:

HOWTO: Use NT Simple TCP/IP Services for Winsock Testing


Author Comment

ID: 2274923
I have tried running the code in the article but it didn't work.
The exe was running but it kept on giving an error "Forcefully disconnected".

I am running windows98 on both machines and not windows NT. Could this be a problem perhaps?

Also when it asks for the server name I type in the other machines name, I hope that's what it means by server name.

What am I doing wrong?
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

LVL 14

Expert Comment

ID: 2275002
The server name is the DNS name or IP address of the system running the DAYTIME protocol TIMESERVER.

You followed the directions exactly and you are clicking the TIME button in the example right? I used the example on a WIN95/WIN98 system and it worked perfectly...

Most likely what is happening is the host you are connecting to does not have a TIMESERVER running on port 13.

There is a quick way to check this...

Open a DOS box and type in at the prompt:

   telnet <servername> 13

where <servername> is the name of the server running the TIMESERVER.

If you get a telnet box that pops open and shows the time and then immediately closes the connection, the server is running the TIMESERVER... If not, you will need to start a TIMESERVER...

Let me know how it turns out....
LVL 14

Expert Comment

ID: 2275011
By the way, here is the code for a TIMESERVER in VB.

Create a new project.

Add a winsock control to the project.

Set the index of the winsock control to 0.

paste the following code into the DECLARATIONS SECTION of the form and run the program... Anyone can then connect to your system on port 13 and they will receive your system clocks time...



Private Sub Form_Load()
    Winsock1(0).LocalPort = 13
End Sub
Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)
    Dim iVal As Integer
    iVal = Winsock1.Count
    Load Winsock1(iVal)
    Winsock1(iVal).Accept requestID
    Winsock1(iVal).SendData CStr(UCase(Format(Now, "DDD MMM dd hh:nn:ss yyyy")))
    Unload Winsock1(iVal)
End Sub
LVL 14

Expert Comment

ID: 2275012
you can quickly test the above VB TIMESERVER by using the following telnet command:

     telnet localhost 13


Expert Comment

ID: 2275395
If you don't mind using dos prompt at your application, you can use:


to get the server time.


Author Comment

ID: 2275892
mcrider you are a legend!!!!!

it worked beautifully. Thank you.

Samuel you are a legend too. If you were quicker i would have given you the points.

This site is the best thing since slice bread as Luke would say.

Thanks guys.

LVL 14

Expert Comment

ID: 2276779
Thanks for the points! Glad I could help!

By the way, NET TIME \\COMPUTERNAME does not use the DAYTIME protocol and only works against Window For Workgroups,WIN95, WIN98, NT and Novell Time Servers...


Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question