【正文】
60。 property區(qū)獲得socket連接使用的handle??梢允褂肏andle property去訪問windows,以便接收來自socket連接的信息。AsyncStyles property決定哪種信息類型是windows handle要接收的。 當(dāng)完成通訊想關(guān)閉socket 連接時(shí),能夠通過調(diào)用Close方法來關(guān)閉連接。連接可能要由服務(wù)器端來關(guān)閉。如果是這種情況,將收到一個(gè)OnDisconnect 事件的通知。 聊天客戶端程序代碼如下:procedure (Sender: TObject)。begin :=。// 。 :=true。 :=false。 :=true。 :=true。:=true。end。procedure (Sender: TObject。 Socket: TCustomWinSocket)。begin :=39。正在連接... 39。+ 。end。procedure (Sender: TObject。 Socket: TCustomWinSocket)。begin :=39。連接到 39。+ 。end。procedure (Sender: TObject)。begin close。end。procedure (Sender: TObject)。begin if then begin (usename+39。*^amp。%^)@39。)。 :=false。 end。 :=39。斷開連接39。 :=true。 :=true。 :=true。 :=true。 。 。end。procedure (Sender: TObject。 var Key: Char)。begin if key=13 then if then 。end。procedure (Sender: TObject)。var chatname : string。 i : integer。begin if =39。39。 then begin showmessage(39。發(fā)送消息不能為空!39。)。 exit。 end。if =true then begin for i:=0 to do begin if [i] then begin chatname:= [i]。 (39。你對39。+chatname+39。悄悄說:39。+)。 //。 break。 end end。 (+39。amp。amp。39。+chatname+39。$$39。+usename+39。%amp。%amp。%amp。39。)。 。 end else begin (+39。對大家說:39。+)。 。 end。end。procedure (Sender: TObject)。begin if =39。39。 then begin showmessage(39。請輸入用戶名!39。)。 。 exit。 end。 if =39。39。 then begin showmessage(39。請輸入密碼!39。)。 。 exit。 end。 (+39。$%$%$%39。)。 usename:=。 password:=。end。procedure (Sender: TObject。 Socket: TCustomWinSocket)。var temptext : string。 //chatname: string。 mssge : string。begin temptext:=。 if pos(39。@$%^amp。39。,temptext)0 then //回送密碼 begin temptext:=copy(temptext,1,length(temptext)6)。 if temptext=password then begin (39。登陸成功,歡迎進(jìn)入本聊天室!39。)。 (usename)。 :=true。 :=false。 :=false。 :=false。 :=true。 end else begin showmessage(39。密碼錯(cuò)誤,登陸失敗,請檢查后重新登陸!39。)。 (usename+39。*^amp。%^)@39。)。 end end else if pos(39。~{}()amp。*%^39。,temptext)0 then // 他人登陸信息 begin temptext:=copy(temptext,1,length(temptext)9)。 if temptext then begin (temptext+39。 進(jìn)入聊天室...39。)。 (temptext)。 end。 end else if pos(39。^$%^$39。,temptext)0 then //off line begin temptext:=copy(temptext,1,length(temptext)6)。 (temptext+39。 離開聊天室...39。)。// showmessage(inttostr((temptext)))。 if (temptext)1 then ((temptext))。 end else if pos(39。$%^amp。*{}39。,temptext)0 then begin mssge:=copy(temptext,1,length(temptext)8)。 (mssge)。 end else (temptext)。end