데브피아 서생일님께서 올리신 팁&강좌 게시판에서 가져온 글입니다.
타입서버에서 표준시간을 얻어오는 방법을 제시해주고 있습니다.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net.Sockets;
namespace NTP_CLIENT
{
class Program
{
static void Main(string[] args)
{
TcpClient tsc = new TcpClient("time-a.nist.gov", 13);
if (tsc.Connected)
{
NetworkStream ns = tsc.GetStream();
StreamReader sr = new StreamReader(ns);
string sResult = sr.ReadToEnd().Trim();
Console.WriteLine(sResult); //서버에서 받은 결과
//공백으로 결과값을 나눠서 배열에 넣음.
string[] saResult = sResult.Split(' ');
foreach (string s in saResult)
{
Console.WriteLine(s);
}
}
else
{
Console.WriteLine("-_-; 연결 안됨");
}
}
}
}
'Program > C#' 카테고리의 다른 글
DoubleBuffer구현을 통한 잔상없애기 (0) | 2010.03.19 |
---|---|
PictureBox에서 Image 깜빡이는 효과주기. (0) | 2010.03.19 |
C#에서 ActiveX 사용하기 (0) | 2010.03.19 |
DateTimePicker 초기값 변경 가능한 NullDateTimePicker (0) | 2010.03.19 |
WebClient 클래스를 이용한 파일 다운로드 문제. (0) | 2010.03.19 |