INDY流的傳送和接收

2022-06-08 19:57:14 字數 801 閱讀 8874

傳送

trys := 'hello world!';

stream := tstringstream.create(s);

idtcpclient1.openwritebuffer;

idtcpclient1.writeinteger(stream.size);//注意這裡:要先寫入流的長度,在讀取的時候如果使用      athread.connection.readstream(stream);

idtcpclient1.writestream(stream, true);

finally

idtcpclient1.closewritebuffer;

stream.free;

end;

接收procedure tserverform.idtcpserver1execute(athread: tidpeerthread);

var stream: tstream;

begin

if not athread.terminated and athread.connection.connected then

begin

stream := tstringstream.create('');

athread.connection.readstream(stream);//這句相當於readstream(stream,-1,false),就是根據流的前四個位元組讀出流長度,然後再將流讀出

stream.position := 0;

memo1.lines.loadfromstream(stream);

end;

indy 10 5 7的資料傳送接收的用法

傳送結構體 tmydata record id integer name array 0.20 of char array 0.10 of char age byte address array 0.256 of char updatetime double end 傳送結構體 procedure ...

indy 10 5 7的資料傳送接收的用法

tmydata record id integer name array 0.20 ofchar array 0.10 ofchar age byte address array 0.256 ofchar updatetime double end 傳送結構體 procedure tform2.bu...

Delphi的Indy通訊中傳送流檔案的注意事項

客戶端傳送流到伺服器端有幾種方式,這裡討論兩種 1.客戶端連線到伺服器後,傳送乙個流,伺服器接收乙個流。procedure tclientform.button3click sender tobject var s string stream tstream begin trys hello wor...