Created
November 11, 2011 19:18
-
-
Save cbrues/1358937 to your computer and use it in GitHub Desktop.
Getting the time from NIST
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text; | |
using System.Net.Sockets; | |
namespace NistTimeQuery { | |
class Program { | |
static void Main( string[] args ) { | |
byte[] buffer = new byte[ 64 ]; | |
/* NIST server listens on port 13 and responds to a TCP connection | |
* with a date/time string. */ | |
Socket s = new Socket( AddressFamily.InterNetwork | |
, SocketType.Stream | |
, ProtocolType.Tcp ); | |
/* This is the IP address for www.nist.gov found at | |
* http://tf.nist.gov/tf-cgi/servers.cgi */ | |
s.Connect( "24.56.178.140" , 13 ); | |
/* The server just sends the string upon connection, no need to send anything. */ | |
int n = s.Receive( buffer ); | |
/* All done with the socket. */ | |
s.Close(); | |
/* Print number of bytes received. */ | |
Console.WriteLine( "{0} bytes received" , n ); | |
/* Print out string. Info on format is at | |
* http://www.nist.gov/pml/div688/grp40/its.cfm */ | |
Console.WriteLine( "{0}" , new string( Encoding.ASCII.GetChars( buffer ) ) ); | |
/* Pause until a key is pressed. */ | |
Console.ReadKey( true ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment