IdTCPClient和IdTcpClient 主要属性和方法


本文整理自网络,侵删。

 该控件包装了一个完整的TCP客户端。该客户端包括sock支持。该控件是以下客户端控件的父类:

TIdDayTime, TIdEcho, TIdFinger, TIdFTP, TIdGopher, TIdHTTP, TIdNNTP, TIdPOP3, TIdQUOTD,

TIdSMTP, TIdTelnet, and TIdWhois。

属性
property BoundIP: string;
客户端使用的IP地址。

property BoundPort: Integer;
当前连接的本地端口号。

property BoundPortMax: Integer;
当前连接时可以使用的最大本地端口号。

property BoundPortMin: Integer;
当前连接可以使用的最小本地端口号。

property Host: string;
远程主机名。可以是IP地址,也可以是域名。

property Port: integer;
远程主机端口号。

property Intercept: TIdConnectionIntercept;
对连接进行读写操作时插入的中途截取者(插件)。

property IOHandler: TIdIOHandler;
发送和接受数据时的输入输出源(插件)。

property MaxLineAction: TIdMaxLineAction;
当读数据时已经到了最大缓冲区长度时触发的动作(事件处理器)。

property MaxLineLength: Integer;
读取数据时最大缓冲区长度(字节数)。

property ReadTimeout: Integer;
读取数据时的超时事件,单位毫秒。

property Socket: TIdIOHandlerSocket;
连接时所用的socket。

方法
procedure Connect(const ATimeout: Integer = IdTimeoutDefault); virtual;
打开客户端连接。

function ConnectAndGetAll: string; virtual;
打开客户端连接并获取所有的数据。

function AllData: string; virtual;
得到连接中所有的数据。

procedure CancelWriteBuffer;
停止写入数据。

procedure Capture(ADest: TStream; const ADelim: string = '.'; const AIsRFCMessage: Boolean =

True); overload;
procedure Capture(ADest: TStream; out VLineCount: Integer; const ADelim: string = '.'; const

AIsRFCMessage: Boolean = True); overload;
procedure Capture(ADest: TStrings; const ADelim: string = '.'; const AIsRFCMessage: Boolean

= True); overload;
procedure Capture(ADest: TStrings; out VLineCount: Integer; const ADelim: string = '.';

const AIsRFCMessage: Boolean = True); overload;
将连接中的数据读取到特殊的对象中去。

procedure CheckForDisconnect(const ARaiseExceptionIfDisconnected: boolean = true;
const AIgnoreBuffer: boolean = false); virtual;
决定是否关闭连接。

procedure CheckForGracefulDisconnect(const ARaiseExceptionIfDisconnected: Boolean = True);

virtual;
决定是否正常地关闭连接。
function CheckResponse(const AResponse: SmallInt; const AAllowedResponses: array
of SmallInt): SmallInt; virtual;
检查允许的响应中的合法的响应。

procedure ClearWriteBuffer;
清除写缓冲区。

procedure CloseWriteBuffer;
关闭写缓冲区。

function Connected: Boolean; virtual;
当前连接是否可用。

function CurrentReadBuffer: string;
从协议栈中更新缓冲区。

procedure Disconnect; virtual;
关闭连接。

procedure FlushWriteBuffer(const AByteCount: Integer = -1);
写入缓存的数据,并清除写缓冲区。

procedure ReadBuffer(var ABuffer; const AByteCount: Longint);
从读取缓冲区中读取数据。

procedure Write(const AOut: string); virtual;
向连接写入数据。

procedure WriteBuffer(const ABuffer; AByteCount: Longint; const AWriteNow: Boolean = False);
向当前连接写入缓冲数据。

procedure WriteStream(AStream: TStream; const AAll: Boolean = True; const AWriteByteCount:

Boolean = False; const ASize: Integer = 0); virtual;
向当前连接写入流数据。

procedure ReadStream(AStream: TStream; AByteCount: LongInt = -1; const AReadUntilDisconnect:

boolean = false);
从当前连接中读取流数据

TIdTCPServer控件

简介
该控件包含一个完整的、多线程TCP服务器。该控件使用一个或者多个线程监听(listen)客户机连接,使用时与TIdThreadMgr联合使用,将每个线程分配给与客户机连接的连接上。

TIdTCPServer提供允许配置服务器监听线程的功能,包括:
DefaultPort
ListenQueue
OnListenException
ReuseSocket
MaxConnections
MaxConnectionReply
该控件也提供控制协议特殊功能的属性和方法,包括:
Greeting
ReplyExceptionCode
ReplyUnknownCommand
该控件用来实现两机之间的连接,支持以下事件:
OnConnect
OnExecute
OnDisconnect
OnException
该控件支持协议命令的控制,包括:
CommandHandlers
CommandHandlersEnabled
OnNoCommandHandler
OnAfterCommandHandler
OnBeforeCommandHandler

该控件是以下控件的父类:
TIdChargenServer, TIdDayTimeServer, TIdDICTServer, TIdEchoServer, TIdFingerServer,

TIdGopherServer, TIdHostNameServer, TIdHTTPServer, TIdIRCServer, TIdNNTPServer, TIdQUOTDServer,

TIdTelnetServer, TIdWhoisServer

一些重要的属性
property ListenQueue: integer;
允许排队未解决的最大监听连接数。

property ReuseSocket: TIdReuseSocket;
本地地址中被重新使用的监听线程。

property MaxConnections: Integer;
最大允许的连接数。

property MaxConnectionReply: TIdRFCReply;
到达最大连接后,返回给其它请求的连接的消息。

property ReplyExceptionCode: Integer;
在发生异常后,返回给连接的代码。

property ReplyTexts: TIdRFCReplies;
服务器实现的协议响应。

property ReplyUnknownCommand: TIdRFCReply;
对未知命令的响应。

property CommandHandlers: TIdCommandHandlers;
命令处理器集合。

property CommandHandlersEnabled: boolean;
在监听线程连接时是否使用命令处理器。

property Greeting: TIdRFCReply;
当监听线程连接成功后发送的标题信息。

相关阅读 >>

Delphi 取得当前监视器的分辨率

Delphi 串口控制继电器

Delphi xe 应用程序横竖屏设置

Delphi 设置系统默认打印机

Delphi处理http请求自定义header

Delphi 修改盘符名称

Delphi中使用activex的一些心得

Delphi stopprocess 进程关闭函数

Delphi xe 共享一个之前封装的多进程共享内存的memorystream

Delphi 文件夹操作

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...