Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

Blazing Fast Socket Communications Component Library For Delphi

NetCom7 is an extremely optimized code on TCP/IP sockets. Forget using one thread per connection. With this suite, you can have as many concurrent connections to your server as you like. Threads are used per request and not per connection, and are maintained in a very fast thread pool class.

The NetCom version 7.2 package is now multi-platform! You can compile your apps under all platforms in FireMonkey as well as VCL!

The implementation begins with TncTCPServer and TncTCPClient which implements the basic socket communications. You can use TncTCPClient and TncTCPServer if all you want is to implement standard (but very fast) socket comms.

On top of the TCP/IP sockets, a lightweight protocol is implemented to be able to pack and unpack buffers (simple TCP/IP is streaming and has no notion of a well-defined buffer). The set of components implementing this functionality is TncServerSource and TncClientSource. Both of these components implement an ExecCommand (aCmd, aData) which triggers an OnHandleCommand event on the other side (a client can ExecCommand to a server, or a server can ExecCommand to any client).

Simple server scenario:

Simple client scenario:

Performance

A simple timing test with the NetCom VS Indy demo gives the following results:

Starting with the base unit, ncSockets.pas, you will see that the implementation does not suffer from slack code, it is rather immediate. The inline calling convention has been used wherever deemed appropriate. The very core functions have been tested and optimized by monitoring the performance via the timing of large loops and assembly inspection to squeeze out every last bit of performance.

The biggest difference though in speed gain is due to the architecture. Unlike most typical sockets: This set of sockets does neither spawn nor use a thread per connection.

This means you can have as many live connections as you like and you will see NO difference in performance! A thread pool just waits for any requests; if a thread was to be created per request or per connection, the speed would suffer a lot, as creating a thread is quite heavy time-wise. If the number of requests per second cannot be handled by the thread pool, the thread pool grows up to a maximum defined size, and if it still cannot cope, the client just waits until the server gets a ready thread to process its request.

The disconnects are picked up immediately, and if a line is so bad that the disconnect cannot be picked up, it tackles this by a keep alive packet by which it gets to know the actual status. There is a Reconnect property and a KeepAlive property. When a client gets disconnected, for whatever reason, it tries to reconnect transparently and without affecting the main application’s performance. This way you do not have to worry about keeping your clients connected.

Compression and encryption are also standard with these components with no extra libraries required. Ofcourse you can use your own compression or encryption if you prefer, but it is rather handy to have just a property you can set on the component.

The effort a programmer has to make to use these components is minimal compared to other frameworks. Please refer to the demos for a better understanding of how to use these components.

Written by Bill Anastasios Demos. Special thanks to Daniel Mauric, Tommi Prami, and Roland Bengtsson for the extensive testing and suggestions.

Source, more informantion and download NetCom7 https://github.com/DelphiBuilder/NetCom7

Exit mobile version