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

4.4. Supporting Multiple Versions of WebSocket Protocol

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

  1. RFC 6455 The WebSocket Protocol December 2011
  2.  
  3. The response from the server might look as follows:
  4.  
  5. HTTP/1.1 400 Bad Request
  6. ...
  7. Sec-WebSocket-Version: 13, 8, 7
  8.  
  9. Note that the last response from the server might also look like:
  10.  
  11. HTTP/1.1 400 Bad Request
  12. ...
  13. Sec-WebSocket-Version: 13
  14. Sec-WebSocket-Version: 8, 7
  15.  
  16. The client now repeats the handshake that conforms to version 13:
  17.  
  18. GET /chat HTTP/1.1
  19. Host: server.example.com
  20. Upgrade: websocket
  21. Connection: Upgrade
  22. ...
  23. Sec-WebSocket-Version: 13
使用WebSocket版本标记字段(`Sec-WebSocket-Version`header字段),客户端可以在最初请求时选择WebSocket协议的版本号(客户端不必要支持最新的版本)。如果服务端支持请求的版本并且我收到消息是有效的,那么服务端会接受这个版本。如果服务端不支持客户端请求的版本,那么服务端必须返回一个`Sec-WebSocket-Version`header字段(或者多个`Sec-WebSocket-Version`header字段)包含服务端支持的所有版本。在这种情况下,如果客户端支持其中任意一个版本,它可以选择一个新的版本值重新发起握手请求。
 
 

Supporting Multiple Versions of WebSocket Protocol 支持多版本WebSocket协议的更多相关文章

  1. The WebSocket Protocol

      [Docs] [txt|pdf] [draft-ietf-hybi-t...] [Diff1] [Diff2] [Errata] Updated by: 7936 PROPOSED STANDAR ...

  2. Netty对WebSocket的支持(五)

    Netty对WebSocket的支持(五) 一.WebSocket简介 在Http1.0和Http1.1协议中,我们要实现服务端主动的发送消息到网页或者APP上,是比较困难的,尤其是现在IM(即时通信 ...

  3. Supporting Multiple Screens 翻译 支持各种屏幕(上)

    Supporting Multiple Screens 支持各种各样的屏幕尺寸.屏幕密度 Android runs on a variety of devices that offer differe ...

  4. Tomcat和Jetty对WebSocket的支持

    公司项目须要,了解了下眼下几种支持WebSocket的框架.曾经用jWebSocket做过一些项目.相对来说.改jWebSocket的源代码略复杂,也不是一天两天能搞定的. 一调研才发现,如今非常多主 ...

  5. 让ie6 7 8 9支持原生html5 websocket

      让ie6 7 8 9支持原生html5 websocket   从github上的 web-socket-js(socket.io好像也是用这个做的他们的flash替代传输方式)改过来的.不过值得 ...

  6. 前后端通信—webSocket(支持跨域)

    WebSocket 的介绍 WebSocket 是什么 WebSocket 是一种网络通信协议.RFC6455 定义了它的通信标准. WebSocket 是 HTML5 开始提供的一种在单个 TCP ...

  7. PHPFarm - How to run multiple versions of PHP on the same computer

    How to Run Multiple Versions of PHP on One Server 转载:http://www.sitepoint.com/run-multiple-versions- ...

  8. Hive的Metastore contains multiple versions

    hive 客户端报错:Exception in thread "main" java.lang.RuntimeException: java.lang.RuntimeExcepti ...

  9. Spark Sql数仓报-Metastore contains multiple versions

    Spark版本为2.1.0,Hadoop版本为2.7.1,元数据存储在mysql中,异常信息如下: Exception in thread "main" java.lang.Run ...

随机推荐

  1. Android驱动学习-app调用内核驱动过程(驱动框架回顾)

    考研已经过去了,android驱动的学习也断了半年多了,现在重新捡起来学习,回顾一下Android驱动的大体框架. Android系统的核心是java,其有一个David虚拟机.Android-app ...

  2. Qt学习笔记-Qt5和Qt4在音频方面的不同-QtAV

    之前学习qt4的时候,播放音频用的是phonon播放后端插件+mplayer. 今天改用qt5了.qt5中去掉了phonon模块加了multimedia.但是依然无法播放音乐,因为没有ffmpge s ...

  3. LInux学习笔记之常用命令

    以下命令主要是平时用到的命令,对于一些经常用到的,就收集资料,归纳一下. 指令目录: 1.yum命令: 2.wget命令: 3.tar命令: 4../configure,make,make insta ...

  4. 【linux】系统编程-5-线程

    目录 前言 7. 线程 7.1 概念 7.2 创建线程 7.2.1 pthread_create() 7.3 设置线程属性 7.3.1 pthread_attr_init() 7.3.2 销毁一个线程 ...

  5. Beta冲刺——第十天(补发)

    这个作业属于哪个课程 https://edu.cnblogs.com/campus/fzzcxy/2018SE1 这个作业要求在哪里 https://edu.cnblogs.com/campus/fz ...

  6. ES6 对象拓展方法

    一,ES6 对象拓展方法 ES6为对象提供了一些拓展方法,下面列举几个比较常见的对象拓展方法.

  7. CPU性能测试——CoreMark篇

    本文将介绍使用CoreMark测试程序对我们小组自研芯片进行性能的测试,记录了CoreMarK工具的使用以及对其测试结果进行分析 测试环境: PC OS: Ubuntu20.04 LTS CPU: 自 ...

  8. 我的开源项目在五个月内超过了 600 star

    其实我在 2016 年年底就开始写了这个项目:Forest,一个能够将 HTTP 的所有请求信息(包括 URL .Header 以及 Body 等信息)绑定到您自定义的 Interface 方法上,能 ...

  9. 对接口报错404 发现url多了一些不可描述的代码%E2%80%8B

    接口url出现了空格,复制的url可能出现空格肉眼看不出来,手动输入一遍URL

  10. shell脚本学习之6小时搞定(6)-重定向及其他

    shell学习之-重定向及其他 目录 shell学习之-重定向及其他 1.输出重定向 2.输入重定向 3.重定向深入讲解 4./dev/null 文件 5.awk Unix 命令默认从标准输入设备(s ...