Requesting Time from Remote Server

Fork501

Freshman
Joined
Jan 27, 2007
Location
Weston, Florida
I was wondering if anyone knows a way to request the time from a remote server without creating a server-side application.

I am writing some time-dependant software and am unable to install anything on the server I need to use for the time. I know that I could just set the host computer to use the server as a time server through Windows, but I want to make sure that I'm pretty accurate down to the second. I don't want to risk something happening that it doesn't update its time and gets off by a second.

I have scoured the internet and this forum for a related issue, but I couldn't find anything.

Thanks in advance for any and all help!

~Derek
 

PlausiblyDamp

Administrator
Joined
Sep 4, 2002
Location
Lancashire, UK
If both the client and server are windows, and there are no firewalls etc. restricting access between them and assuming permissions are correct you could always call the OS' "Net Time \\<server name>" command. However this is going to require you to parse the returned string and might not work for any of the above listed reasons.

If possible it would be easier to get both the client and server to synchronise with a time server (ntp or similar) as this should make the clocks fairly accurate. If you have control over both the client and server applications you could also pass timestamps back and fore as part of your API (i.e. on all requests the client sends it's time and on responses the server returns the original request time and the current server time) - that way you could potentially handle time differences yourself.

Out of interest what does this application do that requires such accurate time keeping between networks applications?
 

Fork501

Freshman
Joined
Jan 27, 2007
Location
Weston, Florida
If both the client and server are windows, and there are no firewalls etc. restricting access between them and assuming permissions are correct you could always call the OS' "Net Time \\<server name>" command. However this is going to require you to parse the returned string and might not work for any of the above listed reasons.

If possible it would be easier to get both the client and server to synchronise with a time server (ntp or similar) as this should make the clocks fairly accurate. If you have control over both the client and server applications you could also pass timestamps back and fore as part of your API (i.e. on all requests the client sends it's time and on responses the server returns the original request time and the current server time) - that way you could potentially handle time differences yourself.

Out of interest what does this application do that requires such accurate time keeping between networks applications?

I like the idea of running NET TIME, but I'm not sure if that can be done in C#. I know that the Shell() command exists in VB, but not C#. Is there a way to do this in C# or do I have to go to VB? (VB used to be my main language, so I will have no problem using it again).

I can't use a time server, because there is a firewall at work and we can't get out to any.

As for the program itself:

I'm the IT manager at a theme park for children. I do a lot of small programs for them, as Application Programming is my major in college and it's my true passion. We are setting up this really cool light show to run automatically. I will be spending the next month programming the Light System to do all of these cool flashes/chases/etc to basically dance to the music that plays over our Audio System. (On a sidebar, programming a Light System for a theme park is cool as hell!)

At this current time, we have no way to link the Audio System and Light System, because they are two different companies and two different networks altogether. I will need to set up a computer with dual network cards to access both. I have a way to plug in a client computer to the Audio System and play music overhead without touching the actual server. I don't have a way to install a server application on the Light System, which is where the remote calls to the computer comes from.

As for the automation of the light system, I can tell it to play my show at specific times throughout the day and it will do it without a hitch. I need a way to play the music at the same time, which is where my application will come in. I want to query the server once an hour or so and update the time on the client computer. I know it seems a bit overboard, but this show needs pinpoint accuracy. I will already be compensating for time spent sending the message to the client to load the audio file and start the show. If I have the times exact, I will remove a "send start" from my design and just have a "send time". Then I am just that more exact.

*wipes forehead* Hope that helped =)

~Derek
 

Fork501

Freshman
Joined
Jan 27, 2007
Location
Weston, Florida
Ok, I found a solution to get the info from a process.

I am using the following code as a guide:

Code:
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName = "NET";
            p.StartInfo.Arguments = "TIME \\" + "\\127.0.0.1";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.CreateNoWindow = true;
            p.Start();
            String toReturn = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
            MessageBox.Show(toReturn);

My problem was that I was using "NET TIME" as the FileName instead of "NET" as the file and including "TIME" in the Arguments.

Thanks again for the help! =)

~Derek
 
Top Bottom