zoukankan      html  css  js  c++  java
  • Supporting Multiple Versions of WebSocket Protocol 支持多版本WebSocket协议

    https://tools.ietf.org/html/rfc6455#section-4.4

    4.4. Supporting Multiple Versions of WebSocket Protocol

    
    
       This section provides some guidance on supporting multiple versions
       of the WebSocket Protocol in clients and servers.
    
       Using the WebSocket version advertisement capability (the
       |Sec-WebSocket-Version| header field), a client can initially request
       the version of the WebSocket Protocol that it prefers (which doesn't
       necessarily have to be the latest supported by the client).  If the
       server supports the requested version and the handshake message is
       otherwise valid, the server will accept that version.  If the server
       doesn't support the requested version, it MUST respond with a
       |Sec-WebSocket-Version| header field (or multiple
       |Sec-WebSocket-Version| header fields) containing all versions it is
       willing to use.  At this point, if the client supports one of the
       advertised versions, it can repeat the WebSocket handshake using a
       new version value.
    
       The following example demonstrates version negotiation described
       above:
    
          GET /chat HTTP/1.1
          Host: server.example.com
          Upgrade: websocket
          Connection: Upgrade
          ...
          Sec-WebSocket-Version: 25
    
    
    
    
    
    
    Fette & Melnikov             Standards Track                   [Page 26]

    
    RFC 6455                 The WebSocket Protocol            December 2011
    
    
       The response from the server might look as follows:
    
          HTTP/1.1 400 Bad Request
          ...
          Sec-WebSocket-Version: 13, 8, 7
    
       Note that the last response from the server might also look like:
    
          HTTP/1.1 400 Bad Request
          ...
          Sec-WebSocket-Version: 13
          Sec-WebSocket-Version: 8, 7
    
       The client now repeats the handshake that conforms to version 13:
    
          GET /chat HTTP/1.1
          Host: server.example.com
          Upgrade: websocket
          Connection: Upgrade
          ...
          Sec-WebSocket-Version: 13
    使用WebSocket版本标记字段(`Sec-WebSocket-Version`header字段),客户端可以在最初请求时选择WebSocket协议的版本号(客户端不必要支持最新的版本)。如果服务端支持请求的版本并且我收到消息是有效的,那么服务端会接受这个版本。如果服务端不支持客户端请求的版本,那么服务端必须返回一个`Sec-WebSocket-Version`header字段(或者多个`Sec-WebSocket-Version`header字段)包含服务端支持的所有版本。在这种情况下,如果客户端支持其中任意一个版本,它可以选择一个新的版本值重新发起握手请求。
     
     
  • 相关阅读:
    年度榜单:2013年最流行的15款免费英文字体
    优秀案例:12个精美的设计工作室 & 设计公司网站
    jQuery Label Better – 友好的表单输入框提示插件
    CSS 魔法系列:纯 CSS 绘制各种图形《系列六》
    Feathers JS – 基于 Express 构建数据驱动的服务
    Node.app – 用于 iOS App 开发的 Node.js 解释器
    100款免费的圣诞节矢量图标素材(PSD & SVG)
    Web 开发人员不能错过的 jQuery 教程和案例
    Headroom.js – 快速响应用户的页面滚动操作
    10个实用的 CSS3 按钮效果制作教程
  • 原文地址:https://www.cnblogs.com/rsapaper/p/12964845.html
Copyright © 2011-2022 走看看