Indy10 控件的使用(2)TidTCpServer组件学习

Indy10 控件的使用(2)TidTCpServer组件学习

(2012-05-18 15:16:53)

转载

标签:

indy10

lazarus

idtcpserver

分类: Indy10

以下来自英文原版帮助文件,文桓英语不好,翻译了老半天。有错误的地方见谅,别骂我。

TIdTCPServer = class(TIdComponent)

Description

TIdTCPServer is a TIdComponent descendant that
encapsulates a complete, multi-threaded TCP (Transmission Control Protocol)
server.

 TIdTCPServer 是 TIdComponent
的子类,封装了一个完整的多线程TCP服务。

TIdTCPServer allows multiple listener threads that
listen for client connections to the server, accept new client connections, and
hand-off execution of the client task to the server. By default, at least one
listener thread is created for the server. For servers with multiple network
adapters, additional socket Bindings can be created that allow the server to
listen for connection requests using the IP address for the selected network
adapter(s).

 TIdTCPServer
允许多个监听线程来监听客户端对服务器的链接,接受新的客服链接,处理客户的任务。默认情况下,至少有一个监听线程在服务器中被创建。在多网卡服务器中,附加的
socket
Bindings被创建,他们用来监听来自特定网卡IP地址的连接请求。

If IP version 6 addresses are enabled for the
server, an additional listener thread is created for each adapter specifically
for connections using the IPv6 address family.

 如果服务器启用了IPv6,一个额外的监听线程将被创建,用来为没一个网卡的使用IPv6地址族的链接服务。

TIdTCPServer allows multiple
simultaneous(同一时刻)
client connections, and allocates a separate
unit of execution for each client connecting to the server. Each client
connection represents a task that is managed by the Scheduler for the server.
Listener threads use the Scheduler to create an executable task for each client
connection.

TIdTCPServer允许同一时刻有多个客户端链接,并为没一个客户链接分配一个单独的执行单元
。每一个客户链接代表了一个任务,这些任务被Scheduler管理。监听线程使用Scheduler来为每一个客户链接创建任务。

The Scheduler handles creation, execution, and
termination of tasks for client connections found in Contexts. The ContextClass
property indicates(指示,表明)
the type of executable task created for client
connections and added to Contexts.

 Scheduler在Contexts里为客户连接处理任务的创建,执行,终止,ContextClass的属性表明了可执行任务的类型。

There are basically two types of Schedulers
available for TIdTCPServer: Thread-based and Fiber-based. Each is designed to
work with a specific type of executable task that represents(代表)
the client connections. There are
further(更进一步) Scheduler
refinements(改进) that allow a pool of
pre-allocated Threads, or Threads which perform scheduling for dependent
Fibers.

 TIdTCPServer有两种基本的Schedulers:基于线程的和基于纤程的。它们为代表客户连接的特定的可执行任务而设计。

The default Scheduler implementation in TIdTCPServer
uses a Thread to represent each client connection. Threads are a common feature
found on all platforms and Operating Systems hosting the Indy
library.

 在TIdTCPServer中默认的Scheduler实现是使用一个线程来代表每一个客户连接的。线程是一个通用的特色,可以工作于不同的操作系统。

But there are performance(性能)
and resource(资源) limitations imposed(强加的) by the platform or Operating System on the number of threads
that can be created. On Windows, for example, the number of threads is limited
by the available virtual memory. By default, every thread gets one
megabyte(兆字节) of stack space and
implies(意味着) a theoretical(理论上的)
limit of 2028 threads. Reducing the default
stack size will allow more threads to be created, but will adversely impact
system performance. In addition, threads are pre-emptively(抢先的) scheduled by the host operating system and allow no
control over execution of the thread process.

 但是由于性能和资源的限制,操作系统只能创建有限数量的线程。例如在windows中,线程的数量取决于可用虚拟内存的大小。默认情况下,每个线程的需要一兆字节的话,意味着理论上只能有2028个线程。减少默认栈大小可以增加线程数量,但是会影响系统性能。线程是抢占式的被操作系统调度,我们没法控制。

Windows addresses these issues by providing the
Fibers API . Essentially, Fibers are a light-weight thread. Fibers require fewer
resources that threads. Fibers can be manually scheduled in the server, and run
in the context of the thread that schedules them. In other words, Fibers are not
pre-emptively scheduled by the Operating System. The Fiber runs when its thread
runs. As a result, servers using the Fiber API can be more scalable(可伸缩的)
than contemporary(同一时代的) thread-based
implementations.

 大意是:windows为了解决这个问题,提供了Fiber
API,纤程是轻量级的线程,需要更少的资源。纤程可以在服务中被人工的调用,而且处于线程的上下文中。

The Fiber API is very different from the Thread API
(even on the Windows platform). To hide these API differences, and to preserve
code portability to non-Windows platforms, the Scheduler in TIdTCPServer
provides an abstraction that masks the differences: the Yarn.

 大意:Fiber API 与Thread
API有很大不同,为了隐藏这些不同,提供了Yarn类。

    Q: What do you get when you weave threads and fibers
together?    A: Yarn.

While TIdTCPServer does not use Fibers unless a
Scheduler supporting Fibers is assigned (TIdSchedulerOfFiber), the Yarn
abstraction is an important one that is central to the use of the Scheduler.
When the Scheduler supports Threads, it deals only with a Yarn at the Thread
level. When the Scheduler supports Fibers, it deals with a Yarn at the Fiber
level.

 TIdTCPServer在不指定的情况下不使用Fiber。

The ContextClass property for the server is used to
create the unit of execution for the client connection, and also uses the Yarn
abstraction.

 服务的ContextClass属性用来为客户链接创建执行单元,也是用Yarn来抽象的。

TIdTCPServer provides properties and methods that
allow configuration of the server and listener threads,
including:

 TIdTCPServer提供的属性和方法来配置服务和监听线程,包括:

Active     
启动

DefaultPort 默认端口

Bindings   

ListenQueue

MaxConnections

IOHandler    IO处理

Intercept    中断

ReuseSocket

TerminateWaitTime

OnAfterBind

OnBeforeListenerRun

OnListenException

The TIdTCPServer architecture provides properties
and methods that allow controlling execution of the client connection tasks for
the server, including:

TIdTCPServer架构提供属性和方法允许控制客户链接任务的执行。 包括:

ContextClass

Scheduler

OnBeforeConnect

OnConnect

OnExecute

OnDisconnect

OnException

During initialization of the TIdTCPServer component,
the following resources are allocated for properties in the
server:

 初始化TidTCPServer控件时,服务中以下属性的资源将被分配:

Bindings

Contexts

During initialization of the TIdTCPServer component,
the following properties are set to their default values:

 初始化阶段的默认值:

Property Value

ContextClass TIdContext class
reference

TerminateWaitTime  5000 (5 seconds)

ListenQueue IdListenQueueDefault

At runtime, TIdTCPServer is controlled by changing
the value in its Active property. When Active is set to True, the following
actions are performed as required to start the server
including:

 运行时,TIdTCPServer通过改变Active属性值来控制。当Active设置为True时,以下操作将被执行:

Bindings
are created and/or initialized for IPv4 and IPv6 addresses.

绑定IP地址

Ensures
that an IOHandler is assigned for the server.

确认IO处理器是否已分配。

Ensures
that a Scheduler is assigned for the server.

确认Scheduler是否已分配。

Creates and
starts listener threads for Bindings using the thread priority
tpHighest.

在每一个Bingdings上创建并启动一个监听线程。

When Active is set to False, the following actions
are performed as required to stop the server including:

 当Active属性设置为False时,执行:

Terminates
and closes the socket handle for the any listener threads.

终止一个监听线程,关闭Socket。

Terminates
and disconnects any client connections in Contexts, and Yarns in
Scheduler.

终止和断开所有客户链接。

Frees an
implicitly(隐藏的) created Scheduler for the server.

释放一个被暗中建立的Scheduler。

Changing
the value in Active in the IDE (design-time) has no effect other than storing
the property value that is used at runtime and during component
streaming.

设计阶段改变Active值没有什么作用,只是存储的值在运行时在工作。

While the
server is Active, listener thread(s) are used to detect and accept client
connection requests. When a connection request is detected, the Scheduler in the
server instance is used to acquire the thread or fiber that controls execution
of the task for the client connection. The IOHandler in the server is used to
get an IOHandler for the client connection.

当服务被激活时,监听线程被用来探测和接受客户请求,当一个链接被探测到时,服务实例中的Scheduler用来获取控制任务执行的线程或者纤程。服务中的IOHandler用来为客户连接获取一个IOHandler。

A client
connection request can be refused for a number of reasons. The listener thread
may get stopped during processing of the request, or the attempt to create a
client IOHandler fails because of an invalid socket handle.

一个客户连接请求可能因为一些原因被拒绝。监听线程可能停止处理请求,或者因为一个无效的socket处理而尝试创建一个客户IOHandler失败。

The most common error occurs when the number of
client connections in Contexts exceeds the number allowed in MaxConnections. In
this situation, an message is written to the client connection that indicates
the condition and the client connection is disconnected.

 最常见的错误发生在客户连接超过最大连接数时。在这种情况下,将向客户端发送一条消息,这个链接也将被关闭。

If the
connection is refused due to any other exception, the OnListenException is
triggered.

如果链接被拒绝是因为其他异常,OnListenException将用来跟踪。

If no error or exception is detected for the
connection request, a TIdContext is created for the client connections
executable task. Procedures that trigger the OnConnect, OnDisconnect, and
OnExecute event handlers are assigned to the context. The context is then given
to the Scheduler for execution using its native thread or fiber
support.

 如果链接请求没有错误,或者异常被检测到,将为这个客户链接任务创建一个TIdContext。处理OnConnect,
OnDisconnect, OnExecute这些事件时使用
Context。这个Context会交给Scheduler。

At this point, the executable task for the client
connection is fully self-contained and controlled using the OnConnect,
OnDisconnect, and OnExecute event handlers. OnConnect and OnDisconnect are
optional, and should be used only to perform simple tasks that are not time
consuming(消费). Using Synchronized method calls that access the main VCL thread
are highly discouraged(气馁的,灰心的). Use OnExecute to control the interaction(相互作用)
between the client and the server during the lifetime of the client
connection.

 

TIdTCPServer does not implement support for any
given protocol used for communication exchanges between clients and the server.
TIdTCPServer can be used as a base class to create custom TCP server descendants
that support specific protocols.

Use TIdCmdTCPServer for a TCP server that includes
TIdCommandHandler and TIdCommand support.

 

Copyright (c) 1993-2004, Chad Z. Hower
(Kudzu) and the Indy Pit Crew. All rights reserved.

时间: 2024-10-10 20:33:47

Indy10 控件的使用(2)TidTCpServer组件学习的相关文章

组件 控件 插件

组件.插件.控件的区别 控件:是编程中用到的,按钮就算是一个控件,窗口也是等等 组件:是软件的一部分.软件的组成部分. 插件:网页中用到的,flash插件,没有它浏览器不能播放flash. 首先范围最广的应该是组件,英文component,提起组件我们不应该把他和具体的技术,什么dll文件,ocx控件,activex等等联系起来,因为组件仅仅是一个概念,如果非要解释的话,那就是凡是在软件开发中用到了软件的复用,被复用的部分都可以称为组件.构件的英文也是component,所以说构件和组件其实是一

控件、组件和插件的区别

(1)组件:首先最广的应该是组件.凡是在软件开发中用到了软件的复用,被复用的部分都可以称为组件. (2)插件:插件是组件中中的一种,凡是在应用程序中已经预留接口的组件就是插件.可以拿IE插件作为例子,IE中之所以可以嵌入很多应用程序,那是因为IE允许他们插入,说的明白一点,那就是在IE的源程序中已经为这些应用程序预留了接口,只要把通知浏览器已经加载了什么插件,浏览器就会调用预留的接口调用这些所谓的插件. (3)控件:控件也是组件中的一种.控件就是具有用户界面的组件(可视化组件),比如:按钮.列表

组件、控件和插件的区别

组件.插件.控件的区别 控件:是编程中用到的,按钮就算是一个控件,窗口也是等等 组件:是软件的一部分.软件的组成部分. 插件:网页中用到的,flash插件,没有它浏览器不能播放flash. 首先范围最广的应该是组件,英文component,提起组件我们不应该把他和具体的技术,什么dll文件,ocx控件,activex等等联系起来,因为组件仅仅是一个概念,如果非要解释的话,那就是凡是在软件开发中用到了软件的复用,被复用的部分都可以称为组件.构件的英文也是component,所以说构件和组件其实是一

iOS使用xib文件创建一个组件为子控件,进行复用

有些情况下,我们发现有一些界面上的控件是可以复用的 如果每次都拷贝这些控件过去,就是比较麻烦.所以,就用一个xib文件,创建一个view,把要复用的控件,放在里面组成一个view,然后在其他的ViewController里面引用就行了. 这样会方便很多. 第一步:创建一个SingleViewApplication,命名为“xib作为子控件复用”,在项目里New File,选择Cocoa Touch Class,命名为"AAView",点击Next,如图1所示: 图 1 第二步:创建一个

最好的Angular2表格控件

最好的Angular2表格控件 现在市面上有大量的JavaScript数据表格控件,包括开源的第三方的和自产自销的.可以说Wijmo的Flexgrid是目前适应Angular 2的最好的表格控件. Angular 2数据表格基本要求: 更小.更快.更熟悉. 为了使用Angular 2表格,首先你需要了解表格的基本要求.FlexGrid开始于1996年,当时使用C++为Visual Basic编写的控件.多年来,它不断进化并在多个平台得到完善,尤其是JavaScript平台.FlexGrid 因为

Webbrowser控件判断网页加载完毕的简单方法

一般情况下,当ReadyState属性变成READYSTATE_COMPLETE时,Webbrowser控件会通过触发DocumentCompleted事件来指示网页加载完毕.但当加载的网页包含frame时,可能会多次触发该事件,所以不能简单地通过它来判断网页加载完毕.从微软的官方网站上了解到,并非每个frame都对应了一个DocumentCompleted事件,只有触发了DownloadBegin事件的frame才会有相应的DocumentCompleted事件.另外,最外层的frame总是最

unity4.6 Beta版 UI控件之Button

最近需求,需要用到4.6版本uGui了,所以抽时间来学习学习,就UI控件在Unity工具里创建预设这块来说相比较于NGUI,我觉得是没有什么太大的区别的. 比如:Canvas--Camera . Text--Label.ImageMask-- Panel 等. 可能是目前4.6版本还不稳定,其UI控件下所挂载的组件脚本代码我们是没法直接点击脚本看到更别说在代码里直接调出修改了,这点就目前来说确实没有NGUI方便. 好了"方不方便"恐怕并不能直接影响每次unity版本的更新带给我们的惊喜

图表控件FlowChart.NET详细介绍及免费下载购买地址

FlowChart.NET是一款专业的.NET平台下的流程图及图表控件,它可以运行在任何C#, VB.NET或Delphi.NET语言编写的软件中.能够帮助你创建工作流程图.对象层次和关系图.网络拓扑图.实体关系图.IVR.工业自动化.genealogy trees .算法流程图.组织结构图.XML文档.类图等,该控件可轻松的整合到您的应用程序中,且不需要太多的程序编写.详细的文档可帮助您快速掌FlowChart.NET的使用方法,且包含了多种编程语言的实例.FlowChart.NET提供多种功

WinForm 无边框窗体和timer控件

一.无边框窗体 1.控制按钮如何制作就是放置可以点击的控件,不局限于使用按钮或是什么别的,只要可以点击能触发点击事件就可以了 做的好看一点,就是鼠标移入,移出,按下三个事件会让按钮改变样式 如何获取图片的相对路径Application.StartupPath + "\\..\\..\\images\\btn_close_highlight.png" \..\文件夹名称... 向上翻一个文件夹 2.如何让窗体动起来调用窗体移动的API 如果有其它控件覆盖了窗体,那么写好鼠标按下的事件委托