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



  • 相关阅读:
    Hystrix源码分析(一)
    docker虚拟ip和项目地ip冲突问题解决
    Hystrix入门demo
    为什么spirng扫描到@compent会把对象注册到容器上
    hive安装与基本操作
    hadoop基本安装
    spring session 存到数据库的设置
    React加Ant Design实现的一个登陆界面及小案例
    一个获取天气预报数据的小案例
    React学习笔记案例2
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/7714406.html
Copyright © 2011-2022 走看看