最快的沟通。
这是NetCom软件包的7.2版。在此版本中,NetCom软件包现在是多平台!您可以在Firemonkey的所有平台下编译您的应用程序!
这组组件是任何语言的最快实现套接字通信的实现。这是TCP/IP插座上非常优化的代码。忘记使用每个连接的线程:使用此套件,您可以随意与服务器具有尽可能多的并发连接。线程是根据请求而不是每个连接使用的,并且在非常快速的线程池类中维护。
实现始于实现基本套接字通信的TNCTCPSERVER和TNCTCPCLIENT。如果您想要的只是实现标准(但很快)插座通信,则可以使用TNCTCPCLIENT和TNCTCPSERVER。
在TCP/IP插座的顶部,实现了轻巧的协议,以打包和解开缓冲区(简单的TCP/IP正在流式传输,并且没有定义明确的缓冲区的概念)。实施此功能的组件集是TNCServersOrce和TNCCLENTSOURCE。这两个组件都实现了execcommand(ACMD,adata),该官方触发另一侧的onhandlecommand事件(客户端可以execcommand到服务器,或者服务器可以execcommand execcommand到任何客户端)。 execCommand可以取决于如何设置其arequiresresult参数,可以阻止或非阻滞(async)。如果您使用阻止行为,则该组件仍会从其同行中处理传入请求。例如,客户库可能正在等待服务器的execcommand,但是在等待时,它可以从服务器提供execCommand请求!
简单的Senario:服务器:
- You put a TncServerSource on your form.
If you want you can change the port it is listening to via the
Port property.
- You implement an OnHandleCommand event handler and,
depending on aCmd parameter (integer), you respond the result of
the command via setting the Result of the OnHandleCommand to
anything you like (TBytes). If an exception is raised while in
HandleCommand, it is trapped, packed, transfered accross to the
calling peer, and raised at the peer's issued ExecCommand.
This way exceptions can be handled as if they were raised locally.
- You set the Active property to true. Your server is ready.
客户:
- You put a TncClientSource on your form.
You can set Host and Port to whatever you want.
- You set Active property to true.
Your client is now connected to the server.
- You call ExecCommand (on your TncClientSource), with any
command number and data that you like. This will send your
command and data over to the server, call its OnHandleCommand,
pack the response, and return it as a result to your ExecCommand.
- ExecCommand is blocking (if aRequiresResult parameter is set to true),
but only for the current command issued.
The TncClientSource's OnHandleCommand still executes, so,
while waiting for a command to return, your client socket may be
processing requests from your server (a server can also
ExecCommand to a client).
- If you have forgotten to set Active to true and call ExecCommand,
the TncClientSource will first try to connect, so you can ommit
setting this property. It will also try to connect if it knows
it has been disconnected (and the Reconnect property is set to true).
这组组件承诺了无与伦比的速度,这不仅在言语中:
NetComvSindy演示的简单计时测试给出了以下结果:
从基本单位NCSOCKET.PAS开始,您会发现该实现不会遭受Slack代码的影响,它是立即的。在认为合适的地方,已使用内联呼叫约定。通过大型循环和组装检查的时间来监视性能,已经测试和优化了核心功能,从而挤出了每一个最后的性能。
速度增益的最大差异是由于体系结构造成的。与最典型的插座不同:
这组插座既没有产卵也不使用每个连接的线程。
这意味着您可以随意拥有尽可能多的实时连接,并且您的性能没有差异!线程池只等待任何请求;如果要根据请求或每个连接创建线程,则速度会很大,因为创建线程的时间很大。如果线程池无法处理每秒的请求数,则线程池的长大到最大定义的大小,并且如果仍然无法应对,则客户端只需等到服务器获取就绪线程即可处理其请求。
也特别注意连接问题。例如,断开连接会立即捡起,如果一条线太糟糕了以至于无法捡起连接,它可以通过保持活着的数据包来解决此问题,从而可以知道实际状态。有一个重新连接的属性和一个存储属性。当客户断开连接时,无论出于何种原因,它都试图透明地重新连接,而不会影响主应用程序的性能。这样,您就不必担心保持客户联系。
压缩和加密也是这些组件的标准配置,不需要额外的库。当然,如果愿意,您可以使用自己的压缩或加密,但是只能在组件上设置一个属性很方便。
这套组件还可以处理向它们投入的垃圾数据,它们已在庞大的全国性项目中使用和测试,可以看到各种攻击。
与其他框架相比,程序员必须努力使用这些组件是最小的。请参考演示,以更好地了解如何使用这些组件。
由Bill Anastasios Demos撰写。特别感谢Daniel Mauric,Tommi Prami,Roland Bengtsson的广泛测试和建议。太感谢了!
vasdemos [at] yahoo [dot] co [dot]英国
** Delphi规则**