implementation
{$R *. DFM}
Procedure Tfrm_Client. Btn_connectClick (Sender: TObject);
The begin
If idtcpclnt1=nil then exit;
If not idtcpclnt1. Connected then
The begin
Try
Idtcpclnt1. Host:=idpwtch1. LocalIP;
Idtcpclnt1. Port:=1119;
Idtcpclnt1. Connect;
Except,
ShowMessage (" connection failed ");
Idtcpclnt1. Disconnect;
The exit
end;
end;
end;
Procedure Tfrm_Client. Btn_sendClick (Sender: TObject);
Var
S: a string;
The begin
S:=edt1. Text;
Idtcpclnt1. IOHandler. Write (S);
end;
This is a server-side
implementation
{$R *. DFM}
Procedure TFrm_Server. Btn_OpenServerClick (Sender: TObject);
The begin
Idtcpsrvr1. Bindings. Add;
Idtcpsrvr1. Bindings. Items [0]. Port:=1119;
Idtcpsrvr1. Bindings. Items [0]. IP:=idpwtch1. LocalIP;
Idtcpsrvr1. Active:=True;
end;
Procedure TFrm_Server. Idtcpsrvr1Execute (AContext: TIdContext);
Var
S: TStringList;
The begin
S:=TStringList. Create;
AContext. Connection. IOHandler. ReadStrings (s);
Mmo1. Lines. The Add (S.T ext);
end;
End.
Can even but does not display the bar I go
CodePudding user response:
Send: idtcpclnt1. IOHandler. Write (S, IndyTextEncoding_UTF8);//specified coding gibberish,Accept when you need to specify the number of rows, the number of rows to add before data transfer, receive 1 row: AContext. Connection. The IOHandler. ReadStrings (S, 1, IndyTextEncoding_UTF8);
Transceiver can also use WriteLn and ReadLn, need not consider the number of lines, in addition, the string list need to release, or a memory leak,
CodePudding user response: