(1) unit u_echo_client;inte***ce
uses
windows, messages, sysutils, variants, classes, graphics, controls, forms,
dialogs, idbasecomponent, idcomponent, idtcpconnection, idtcpclient,
idecho, stdctrls;
type
techo_client = class(tform)
label1: tlabel;
label2: tlabel;
label3: tlabel;
label4: tlabel;
bconnect: tbutton;
bsend: tbutton;
bdiscon: tbutton;
eaddress: tedit;
etext: tedit;
ltime: tlabel;
lreceive: tlabel;
idecho1: tidecho;
procedure bconnectclick(sender: tobject);
procedure bsendclick(sender: tobject);
procedure bdisconclick(sender: tobject);
procedure formcreate(sender: tobject);
procedure formclosequery(sender: tobject; var canclose: boolean);
procedure eaddresschange(sender: tobject);
private
public
end;
var echo_client: techo_client;
implementation
procedure techo_client.formcreate(sender: tobject);
begin
bconnect.enabled := true; //啟用「連線」按鈕
etext.enabled := false; //禁用傳送文字框
etext.color := clsilver;
bsend.enabled :=false; //禁用「傳送」按鈕
bdiscon.enabled := false; //禁用「斷開連線」按鈕
end;
procedure techo_client.formclosequery(sender: tobject;
var canclose: boolean);
begin
idecho1.disconnect;
end;
procedure techo_client.eaddresschange(sender: tobject);
begin
// 設定要連線的伺服器的位址
idecho1.host := eaddress.text;
end;
procedure techo_client.bconnectclick(sender: tobject);
begin
try//建立與echo伺服器的連線
idecho1.connect;
etext.enabled := true; //啟用傳送文字框
etext.color := clwhite;
bsend.enabled := true;//啟用「傳送」按鈕
bdiscon.enabled := true;//啟用「斷開連線」按鈕
bconnect.enabled :=false;//禁用「連線」按鈕
except
//斷開與echo伺服器的連線
idecho1.disconnect;
showmessage('連線失敗,請檢查伺服器是否執行!');
end; //try..except
end;
procedure techo_client.bsendclick(sender: tobject);
begin
//對傳送文字框的內容不為『』的情況進行處理
if etext.text<>'' then
begin
//傳送並接收回聲資料
ltime.caption := idecho1.echo ( etext.text );
//顯示傳送和接收回聲資料所需的時間
lreceive.caption := inttostr ( idecho1.echotime );
end//對傳送文字框的內容為『』的情況進行處理
else
begin
ltime.caption :='';
lreceive.caption :='';
end;
end;
procedure techo_client.bdisconclick(sender: tobject);
begin
//斷開與echo伺服器的連線
idecho1.disconnect;
bconnect.enabled := true; //啟用「連線」按鈕
etext.enabled := false; //禁用傳送文字框
etext.color := clsilver;
bsend.enabled :=false; //禁用「傳送」按鈕
bdiscon.enabled := false; //禁用「斷開連線」按鈕
end;
end.
(2) unit u_echo_server;
inte***ce
uses
windows, messages, sysutils, variants, classes, graphics, controls, forms,
dialogs, stdctrls, idbasecomponent, idcomponent, idtcpserver,
idechoserver;
type
tf_echo_server = class(tform)
label1: tlabel;
label2: tlabel;
button1: tbutton;
idechoserver1: tidechoserver;
procedure button1click(sender: tobject);
procedure formactivate(sender: tobject);
procedure idechoserver1disconnect(athread: tidpeerthread);
procedure idechoserver1connect(athread: tidpeerthread);
private
public
end;
var f_echo_server: tf_echo_server;
implementation
procedure tf_echo_server.formactivate(sender: tobject);
begin
try//啟用tidechoserver元件
idechoserver1.active := true;
except
showmessage('拒絕連線!由於安全的原因無法繫結到預定的埠!');
end;
end;
procedure tf_echo_server.idechoserver1disconnect(athread: tidpeerthread);
begin
//更新窗體上顯示的伺服器狀態
label2.caption := '[ 空閒-等待新使用者 ]';
end;
procedure tf_echo_server.idechoserver1connect(athread: tidpeerthread);
begin
//更新窗體上顯示的伺服器狀態
label2.caption := '[ 服務於客戶 ]';
end;
procedure tf_echo_server.button1click(sender: tobject);
begin
if idechoserver1.active then
idechoserver1.active := false;
end;
end.
網路應用 web應用
world wide web tim berners lee 網頁 網頁互相鏈結 網頁 web page 包含多個物件 objects 物件的定址 addressing url uniform resoure locator 統一資源定位器 rfc1738 scheme host port path...
應用 原生應用和混合應用的區別
最近原生應用 web應用 混合應用的名字讓我們聽得比較熟悉了,現在我們就通過評析各種應用的優缺點來更進一步看看這三者的區別。一.原生應用 你使用過微軟powerpoint 或者 word吧?這些可直接在你電腦上執行或者在智慧型手機上執行,簡單來說,原生應用是特別為某種作業系統開發的,比如ios an...
Flyme應用中心應用認領
使用jarsigner 他推薦的命令如下 jarsigner verbose keystore c downloads sign verification mykeystore signedjar meizuemptyapk release signed apk meizuemptyapk rele...