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