1、ReadFromStack
原型:function ReadFromStack(const ARaiseExceptionIfDisconnected: boolean; const ATimeout: integer; const AUseBuffer: boolean; ADestStream: TIdBuffer): integer; virtual;
用于判断缓冲区里是否还有数据可读,返回值:Integer - Number of bytes read.
2、CurrentReadBuffer
原型:function CurrentReadBuffer: string;
用于读取Socket数据到缓冲区,注意返回为String类型,如果直接显示该String的数据,对于\0之后的数据可能看不到,因此要读取所有的数据,还必须利用CurrentReadBufferSize()判断该String的长度。
返回值:String - Contents of the Indy buffer.
3、GetResponse
原型:function GetResponse(const AAllowedResponses: Array of SmallInt): SmallInt; virtual;
对于简单的命令应答可以使用这个方法获取应答消息,返回值:SmallInt - The numeric response number.
4、ReadBuffer
原型:procedure ReadBuffer(var ABuffer; const AByteCount: Longint);
读取指定数目的字节到缓冲区ABuffer,注意它会调用 ReadFromStack 以检查缓冲区里的数据是否少于AByteCount
5、ReadInteger
原型:function ReadInteger(const AConvert: boolean): Integer;
从缓冲区中读取整型数据,它会调用ReadBuffer
6、ReadLn
原型:function ReadLn(const ATerminator: string; const ATimeout: integer): string; virtual;
读取移行记录,带有一个TimeOut属性,以防止在读不到新行时死循环。返回值:String - Line read from the buffer.
注意行分隔符可能是以下几种:
#0 - Default Line Feed (#10)
LF - Line Feed (#10)
CR - Carriage Return (#13)
EOL - End-of-line (Carriage Return + Line Feed)
7、ReadLnWait:
原型:function ReadLnWait: string;
很像ReadLn,但它会一直傻傻的等待
8、ReadSmallInt
原型:function ReadSmallInt(const AConvert: boolean): SmallInt;
9、ReadStream
原型:procedure ReadStream(AStream: TStream; AByteCount: LongInt; const AReadUntilDisconnect: boolean);
10、ReadString
原型:function ReadString(const ABytes: integer): string;
与CurrentReadBuffer的不同在于它读取指定长度的字符串
procedure
TReadThread.Execute;
var i:integer;
s: string ;
begin
try
while (Terminated = false) and (IdTCPClient1.Connected = true) do
begin
i: = IdTCPClient1.ReadFromStack(); // 检查是否需要读取数据
if i > 0 then
begin
s: = IdTCPClient1.ReadString(i); // 读取数据
end ;
SleepEx( 100 ,true);
end ; // loop
except
end ;
end ;
出处:http://blog.nnsky.com/blog_view_17131.html
var i:integer;
s: string ;
begin
try
while (Terminated = false) and (IdTCPClient1.Connected = true) do
begin
i: = IdTCPClient1.ReadFromStack(); // 检查是否需要读取数据
if i > 0 then
begin
s: = IdTCPClient1.ReadString(i); // 读取数据
end ;
SleepEx( 100 ,true);
end ; // loop
except
end ;
end ;