mormot支持websocket


mormot支持websocket

根據定義,HTTP連接是無狀態的和單向的,也就是說,客戶機向服務器發送一個請求,該服務器通過一個應答回復。
沒有客戶端的預先請求,就沒有辦法讓服務器發送消息給客戶機。

WebSockets是能讓普通的HTTP連接升級為雙路通信有線通信協議。
在安全握手之后,底層TCP/IP套接字能夠通過一組輕量級協議直接訪問應用程序定義的協議,而不需要HTTP開銷。

synbidirsock.pas單元實現底層服務器和客戶端WebSocket通信。

 

服務端:

uses mORMotHttpServer

 HttpServer := TSQLHttpServer.Create('8888',[Server],'+',useBidirSocket);
Under the hood, it will instantiate a TWebSocketServer HTTP server, as defined in mORMotHttpServer.pas, based on the sockets API, able to upgrade the HTTP protocol into WebSockets.
Our High-performance http.sys server is not yet able to switch to WebSockets - and at API level, it would require at least Windows 8 or Windows 2012 Server.

Then you enable WebSockets for the TWebSocketProtocolBinary protocol, with an encryption key:

   HttpServer.WebSocketsEnable(Server,'key');

客戶端:
Client := TSQLHttpClientWebsockets.Create('127.0.0.1','8888',TSQLModel.Create([]));
  Client.WebSocketsUpgrade('key');
除了常規的查詢/應答命令定義客戶端服務器的服務通過接口,還可以使用接口參數的服務定義回調方法。




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM