Link to home
Start Free TrialLog in
Avatar of aussie_guy_nik
aussie_guy_nik

asked on

Reading Computer's clock over a network

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.
Avatar of aussie_guy_nik
aussie_guy_nik

ASKER

No comment
ASKER CERTIFIED SOLUTION
Avatar of mcrider
mcrider

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 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....
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...


Cheers!


THE CODE:

Private Sub Form_Load()
    Winsock1(0).LocalPort = 13
    Winsock1(0).Listen
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")))
    DoEvents
    Winsock1(iVal).Close
    DoEvents
    Unload Winsock1(iVal)
End Sub
you can quickly test the above VB TIMESERVER by using the following telnet command:


     telnet localhost 13


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

NET TIME \\COMPUTERNAME

to get the server time.

Samuel
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.

Mezzenga
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...


Cheers!