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');
除了常規的查詢/應答命令定義客戶端服務器的服務通過接口,還可以使用接口參數的服務定義回調方法。
