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');
除了常规的查询/应答命令定义客户端服务器的服务通过接口,还可以使用接口参数的服务定义回调方法。



posted @ 2017-10-23 08:40  delphi中间件  阅读(3644)  评论(0编辑  收藏  举报