最快的溝通。
這是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規則**