線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2175
推到 Plurk!
推到 Facebook!

連NTP Server的程式有問題

尚未結案
超級賽亞人3
一般會員


發表:38
回覆:53
積分:23
註冊:2007-06-05

發送簡訊給我
#1 引用回覆 回覆 發表時間:2010-06-18 13:26:26 IP:163.17.xxx.xxx 訂閱
我欲連上NTP server :tock.stdtime.gov.tw
他的IP位置為220.130.158.71
可是我不知道他的Port是多少

這是C Builder 6 完全攻略裡的一個範例
可以執行,但卻跑步出結果

請問知道的大大,這部分要改那邊,才能接收到時間呢?

[code cpp]
//---------------------------------------------------------------------------

#include
#pragma hdrstop

#include "main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
//使用NMDayTime抓取Server的Date and Time

//如果Server Host和Port皆有輸入才連線去抓取資料
if ((LabeledEdit1->Text != "") && (LabeledEdit2->Text != ""))
{
//將相關的值設定到變數..方便使用
AnsiString Server = LabeledEdit1->Text;
int Port = LabeledEdit2->Text.ToInt();

//指定Server Host以及Server Port
NMDayTime1->Host = Server;
NMDayTime1->Port = Port;

//抓取Server端的DateTime
LabeledEdit3->Text = NMDayTime1->DayTimeStr;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMDayTime1ConnectionFailed(TObject *Sender)
{
//當NMDayTime連線錯誤時發生的事件
MessageBox(GetActiveWindow(), "連線失敗!\n", NULL, MB_OK|MB_ICONERROR);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMDayTime1InvalidHost(bool &Handled)
{
//當NMDayTime發現輸入的Server Host不合法所發生的事件
MessageBox(GetActiveWindow(), "不合法的位址!\n", NULL, MB_OK|MB_ICONERROR);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
//使用NMTime抓取Server的Time

//如果Server Host和Port皆有輸入才連線去抓取資料
if ((LabeledEdit4->Text != "") && (LabeledEdit6->Text != ""))
{
//將相關的值設定到變數..方便使用
AnsiString Server = LabeledEdit4->Text;
int Port = LabeledEdit6->Text.ToInt();

//指定Server Host以及Server Port
NMTime1->Host = Server;
NMTime1->Port = Port;

//抓取Server端的Time
LabeledEdit5->Text = NMTime1->TimeStr;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMTime1ConnectionFailed(TObject *Sender)
{
//當NMTime連線錯誤時發生的事件
MessageBox(GetActiveWindow(), "連線失敗!\n", NULL, MB_OK|MB_ICONERROR);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMTime1InvalidHost(bool &Handled)
{
//當NMTime發現輸入的Server Host不合法所發生的事件
MessageBox(GetActiveWindow(), "不合法的位址!\n", NULL, MB_OK|MB_ICONERROR);
}
//---------------------------------------------------------------------------
[/code]

系統時間:2024-04-27 5:58:34
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!