爆款云主机2核4G限时秒杀,88元/年起!
查看详情

活动

天翼云最新优惠活动,涵盖免费试用,产品折扣等,助您降本增效!
热门活动
  • 618智算钜惠季 爆款云主机2核4G限时秒杀,88元/年起!
  • 免费体验DeepSeek,上天翼云息壤 NEW 新老用户均可免费体验2500万Tokens,限时两周
  • 云上钜惠 HOT 爆款云主机全场特惠,更有万元锦鲤券等你来领!
  • 算力套餐 HOT 让算力触手可及
  • 天翼云脑AOne NEW 连接、保护、办公,All-in-One!
  • 中小企业应用上云专场 产品组合下单即享折上9折起,助力企业快速上云
  • 息壤高校钜惠活动 NEW 天翼云息壤杯高校AI大赛,数款产品享受线上订购超值特惠
  • 天翼云电脑专场 HOT 移动办公新选择,爆款4核8G畅享1年3.5折起,快来抢购!
  • 天翼云奖励推广计划 加入成为云推官,推荐新用户注册下单得现金奖励
免费活动
  • 免费试用中心 HOT 多款云产品免费试用,快来开启云上之旅
  • 天翼云用户体验官 NEW 您的洞察,重塑科技边界

智算服务

打造统一的产品能力,实现算网调度、训练推理、技术架构、资源管理一体化智算服务
智算云(DeepSeek专区)
科研助手
  • 算力商城
  • 应用商城
  • 开发机
  • 并行计算
算力互联调度平台
  • 应用市场
  • 算力市场
  • 算力调度推荐
一站式智算服务平台
  • 模型广场
  • 体验中心
  • 服务接入
智算一体机
  • 智算一体机
大模型
  • DeepSeek-R1-昇腾版(671B)
  • DeepSeek-R1-英伟达版(671B)
  • DeepSeek-V3-昇腾版(671B)
  • DeepSeek-R1-Distill-Llama-70B
  • DeepSeek-R1-Distill-Qwen-32B
  • Qwen2-72B-Instruct
  • StableDiffusion-V2.1
  • TeleChat-12B

应用商城

天翼云精选行业优秀合作伙伴及千余款商品,提供一站式云上应用服务
进入甄选商城进入云市场创新解决方案
办公协同
  • WPS云文档
  • 安全邮箱
  • EMM手机管家
  • 智能商业平台
财务管理
  • 工资条
  • 税务风控云
企业应用
  • 翼信息化运维服务
  • 翼视频云归档解决方案
工业能源
  • 智慧工厂_生产流程管理解决方案
  • 智慧工地
建站工具
  • SSL证书
  • 新域名服务
网络工具
  • 翼云加速
灾备迁移
  • 云管家2.0
  • 翼备份
资源管理
  • 全栈混合云敏捷版(软件)
  • 全栈混合云敏捷版(一体机)
行业应用
  • 翼电子教室
  • 翼智慧显示一体化解决方案

合作伙伴

天翼云携手合作伙伴,共创云上生态,合作共赢
天翼云生态合作中心
  • 天翼云生态合作中心
天翼云渠道合作伙伴
  • 天翼云代理渠道合作伙伴
天翼云服务合作伙伴
  • 天翼云集成商交付能力认证
天翼云应用合作伙伴
  • 天翼云云市场合作伙伴
  • 天翼云甄选商城合作伙伴
天翼云技术合作伙伴
  • 天翼云OpenAPI中心
  • 天翼云EasyCoding平台
天翼云培训认证
  • 天翼云学堂
  • 天翼云市场商学院
天翼云合作计划
  • 云汇计划
天翼云东升计划
  • 适配中心
  • 东升计划
  • 适配互认证

开发者

开发者相关功能入口汇聚
技术社区
  • 专栏文章
  • 互动问答
  • 技术视频
资源与工具
  • OpenAPI中心
开放能力
  • EasyCoding敏捷开发平台
培训与认证
  • 天翼云学堂
  • 天翼云认证
魔乐社区
  • 魔乐社区

支持与服务

为您提供全方位支持与服务,全流程技术保障,助您轻松上云,安全无忧
文档与工具
  • 文档中心
  • 新手上云
  • 自助服务
  • OpenAPI中心
定价
  • 价格计算器
  • 定价策略
基础服务
  • 售前咨询
  • 在线支持
  • 在线支持
  • 工单服务
  • 建议与反馈
  • 用户体验官
  • 服务保障
  • 客户公告
  • 会员中心
增值服务
  • 红心服务
  • 首保服务
  • 客户支持计划
  • 专家技术服务
  • 备案管家

了解天翼云

天翼云秉承央企使命,致力于成为数字经济主力军,投身科技强国伟大事业,为用户提供安全、普惠云服务
品牌介绍
  • 关于天翼云
  • 智算云
  • 天翼云4.0
  • 新闻资讯
  • 天翼云APP
基础设施
  • 全球基础设施
  • 信任中心
最佳实践
  • 精选案例
  • 超级探访
  • 云杂志
  • 分析师和白皮书
  • 天翼云·创新直播间
市场活动
  • 2025智能云生态大会
  • 2024智算云生态大会
  • 2023云生态大会
  • 2022云生态大会
  • 天翼云中国行
天翼云
  • 活动
  • 智算服务
  • 产品
  • 解决方案
  • 应用商城
  • 合作伙伴
  • 开发者
  • 支持与服务
  • 了解天翼云
      • 文档
      • 控制中心
      • 备案
      • 管理中心

      WebSocket-Over-HTTP Protocol

      首页 知识中心 其他 文章详情页

      WebSocket-Over-HTTP Protocol

      2023-06-29 08:36:10 阅读次数:420

      HTTP,server,WebSocket

      WebSocket-Over-HTTP Protocol

      WebSocket-Over-HTTP Protocol

      The WebSocket-Over-HTTP protocol is a simple, text-based protocol for gatewaying between a WebSocket client and a conventional HTTP server.

      Why?

      Pushpin’s Generic Realtime Intermediary Protocol (GRIP) enables out-of-band message injection into WebSocket connections. Normally, using GRIP with WebSockets requires a WebSocket connection on both sides of the proxy:

      Client <--WS--> GRIP Proxy <--WS--> Server
      

      The GRIP Proxy is a publish/subscribe service. When the server has data to send spontaneously, it does not use its WebSocket connection to send the data. Rather, it uses an out-of-band publish command to the proxy (usually via HTTP POST). This means that the WebSocket connection between the proxy and the server is used almost exclusively for servicing incoming requests from the client.

      If the communication path between the proxy and the server only needs to handle request/response interactions, then HTTP becomes a viable alternative to a WebSocket:

      Client <--WS--> GRIP Proxy <--HTTP--> Server
      

      Using HTTP for communication between the proxy and server may be easier to maintain and scale since HTTP server tools are well established. Plus, if the server is merely doing stateless RPC processing, then HTTP is arguably a respectable choice for this tier in the service.

      Of course, the usefulness of this gatewaying is entirely dependent on the server having a way to send data to clients out-of-band. As such, it is recommended that the WebSocket-Over-HTTP protocol be used in combination with GRIP. Note, however, that the WebSocket-Over-HTTP protocol does not explicitly depend on GRIP.

      Protocol

      The gateway and server exchange WebSocket “events” via HTTP requests and responses. The following events are defined:

      • OPEN - WebSocket negotiation request or acknowledgement.
      • TEXT, BINARY - Messages with content.
      • PING, PONG - Ping and pong messages.
      • CLOSE - Close message with 16-bit close code.
      • DISCONNECT - Indicates connection closed uncleanly or does not exist.

      Events are encoded in a format similar to HTTP chunked transfer encoding:

      TEXT B\r\n
      hello world\r\n
      

      The format is the name of the event, a space, the hexidecimal encoding of the content size, a carriage return and newline, the content bytes, and finally another carriage return and newline.

      For events with no content, the size and content section can be omitted:

      OPEN\r\n
      

      Events with content are TEXT, BINARY, and CLOSE. Events without content are OPEN, PING, PONG, and DISCONNECT.

      An event that should not contain content MAY be encoded with content. Receivers should ignore such content. For example, this is legal:

      OPEN 0\r\n
      \r\n
      

      One or more encoded events are then concatenated and placed in the body of an HTTP request or response, with content type application/websocket-events.

      Example

      Gateway opens connection:

      POST /target HTTP/1.1
      Connection-Id: b5ea0e11
      Content-Type: application/websocket-events
      [... any headers included by the client WebSocket handshake ...]
      
      OPEN\r\n
      

      Server accepts connection:

      HTTP/1.1 200 OK
      Content-Type: application/websocket-events
      [... any headers to include in the WebSocket negotiation response ...]
      
      OPEN\r\n
      

      Gateway relays message from client:

      POST /target HTTP/1.1
      Connection-Id: b5ea0e11
      Content-Type: application/websocket-events
      
      TEXT 5\r\n
      hello\r\n
      

      Server responds with two messages:

      HTTP/1.1 200 OK
      Content-Type: application/websocket-events
      
      TEXT 5\r\n
      world\r\n
      TEXT 1C\r\n
      here is another nice message\r\n
      

      Gateway relays a close message:

      POST /target HTTP/1.1
      Connection-Id: b5ea0e11
      Content-Type: application/websocket-events
      
      CLOSE 2\r\n
      [... binary status code ...]\r\n
      

      Server sends a close message back:

      HTTP/1.1 200 OK
      Content-Type: application/websocket-events
      
      CLOSE 2\r\n
      [... binary status code ...]\r\n
      

      State Management

      Headers of the initial WebSocket negotiation request MUST be replayed with every request made by the gateway. This means that if the client uses cookies or other headers for authentication purposes, the server will receive this data with every message.

      The gateway includes a Connection-Id header which uniquely identifies a particular client connection. Servers that need to track connections can use this. In most cases, though, servers should not have to care about connections.

      It is possible to bind metadata to the connection via a Set-Meta-* header. This works similar to a cookie. The server can set a field that the gateway should echo back on all subsequent requests.

      For example, a client supplies a cookie which the gateway relays across during connect:

      POST /target HTTP/1.1
      Connection-Id: b5ea0e11
      Content-Type: application/websocket-events
      Cookie: [... auth info ...]
      
      OPEN\r\n
      

      The server accepts the connection and binds a User field based on the cookie:

      HTTP/1.1 200 OK
      Content-Type: application/websocket-events
      Set-Meta-User: alice
      
      OPEN\r\n
      

      Now, any further requests from the gateway will include a Meta-User header:

      POST /target HTTP/1.1
      Connection-Id: b5ea0e11
      Meta-User: alice
      Content-Type: application/websocket-events
      
      TEXT 5\r\n
      hello\r\n
      

      Security note: gateways MUST NOT relay any headers from the client that are prefixed with Meta-. This prevents the client from spoofing metadata bindings. Additionally, the server needs to ensure that an incoming request came from a gateway before trusting its Meta-* headers.

      Notes

      • The first request MUST contain an OPEN event as the first event.
      • The first response MUST contain an OPEN event as the first event.
      • If the server tracks connections and no longer considers the connection to exist, it should respond with DISCONNECT. In most cases, servers will not track connections, though.
      • Gateway should only have one outstanding request per client connection. This ensures in-order delivery.
      • DISCONNECT event only sent if connection was not closed cleanly. With clean close, disconnect is implied.
      • Within this protocol alone, the server has no way to talk to the client outside of responding to incoming requests.
      • Gateway can send an empty request to keep-alive the current connection. The gateway shall consider an empty response to be a keep-alive from the server. The server enables keep-alives by providing a Keep-Alive-Interval response header.
      版权声明:本文内容来自第三方投稿或授权转载,原文地址:https://blog.51cto.com/rongfengliang/3131111,作者:rongfengliang,版权归原作者所有。本网站转在其作品的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如因作品内容、版权等问题需要同本网站联系,请发邮件至ctyunbbs@chinatelecom.cn沟通。

      上一篇:VictoriaMetrics 集成karma

      下一篇:memsql filesystem pipeline 试用

      相关文章

      2025-05-14 10:02:58

      java项目多端数据同步解决方案

      多端数据同步是指在多个设备(例如桌面应用、移动应用、Web应用)之间保持数据的一致性。

      2025-05-14 10:02:58
      java , Spring , WebSocket , 同步 , 数据 , 版本号
      2025-05-09 09:21:53

      WebAPI 和 webservice的区别

      WebAPI 和 webservice的区别

      2025-05-09 09:21:53
      HTTP , 协议 , 客户端 , 服务器 , 请求
      2025-04-22 09:28:31

      Tcp的三次握手及netty和实际开发如何设置全连接队列参数

      Tcp的三次握手及netty和实际开发如何设置全连接队列参数

      2025-04-22 09:28:31
      queue , server , 队列
      2025-04-09 09:16:42

      Python爬虫应用指南之基础知识

      Python适合在诸多领域的应用,作为软件测试从业者,具备一定的自动化测试基础,再去开展Python爬虫工程应用是更加有优势的。

      2025-04-09 09:16:42
      HTTP , Session , 代理 , 爬虫 , 网页
      2025-04-09 09:15:47

      nginx负载均衡 多服务器代码同步更新(envoy)

      nginx负载均衡 多服务器代码同步更新(envoy)

      2025-04-09 09:15:47
      composer , server , task , 样例
      2025-04-09 09:13:27

      PHP代码审计————7、\tPHP代码审计之输入验证和输出显示

      PHP代码审计————7、\tPHP代码审计之输入验证和输出显示

      2025-04-09 09:13:27
      amp , file , HTTP , PHP , 函数 , 变量 , 输入
      2025-04-09 09:11:38

      redis配置参数详细说明

      redis配置参数详细说明

      2025-04-09 09:11:38
      conf , redis , server , 默认
      2025-03-28 07:41:43

      使用 Axios 拦截器优化 HTTP 请求与响应的实践

      使用 Axios 拦截器优化 HTTP 请求与响应的实践

      2025-03-28 07:41:43
      Axios , HTTP , 代码 , 响应 , 拦截器 , 请求
      2025-03-26 09:33:14

      前端怎么间接控制浏览器的缓存行为

      前端开发中确实可以通过多种方式影响和控制浏览器缓存的行为,但前端代码本身不能直接修改浏览器的缓存数据。

      2025-03-26 09:33:14
      HTTP , 前端 , 浏览器 , 缓存 , 资源
      2025-03-18 08:27:10

      nginx:400 Bad RequestThe plain HTTP request

      nginx:400 Bad RequestThe plain HTTP request

      2025-03-18 08:27:10
      HTTP , nginx
      查看更多
      推荐标签

      作者介绍

      天翼云小翼
      天翼云用户

      文章

      33561

      阅读量

      5266826

      查看更多

      最新文章

      nginx:400 Bad RequestThe plain HTTP request

      2025-03-18 08:27:10

      【快速搭建】kafka基础(2):kafka quickstart

      2025-03-11 09:36:54

      【连接】TCP长连接和短连接-HTTP(史上最通俗!2.0)

      2025-02-25 08:54:43

      kafka集群重启方法

      2025-01-08 08:39:56

      response.setHeader用法总结

      2024-12-06 06:22:10

      【DRF】请求和响应对象(7)

      2024-11-25 09:13:35

      查看更多

      热门文章

      SQL SERVER 2005 DBCC IND命令说明

      2023-04-23 09:32:49

      postgres pg_cron 扩展连接远程pg server

      2023-04-07 06:40:15

      精讲响应式WebClient第4篇-文件上传与下载

      2023-05-23 08:22:30

      HTTP常用的方法和状态码

      2023-05-15 10:01:25

      在终端上使用elinks下载github上单个文件

      2024-07-01 01:31:38

      异步发送HTTP请求

      2023-06-26 08:41:21

      查看更多

      热门标签

      linux java python javascript 数组 前端 docker Linux vue 函数 shell git 节点 容器 示例
      查看更多

      相关产品

      弹性云主机

      随时自助获取、弹性伸缩的云服务器资源

      天翼云电脑(公众版)

      便捷、安全、高效的云电脑服务

      对象存储

      高品质、低成本的云上存储服务

      云硬盘

      为云上计算资源提供持久性块存储

      查看更多

      随机文章

      SQL SERVER 2005 DBCC IND命令说明

      Zygote启动流程

      sql server中查询正在执行的sql

      【快速搭建】kafka基础(2):kafka quickstart

      Tomcat简介及端口号被占用的解决方法

      Nginx WebSocket proxying example

      • 7*24小时售后
      • 无忧退款
      • 免费备案
      • 专家服务
      售前咨询热线
      400-810-9889转1
      关注天翼云
      • 旗舰店
      • 天翼云APP
      • 天翼云微信公众号
      服务与支持
      • 备案中心
      • 售前咨询
      • 智能客服
      • 自助服务
      • 工单管理
      • 客户公告
      • 涉诈举报
      账户管理
      • 管理中心
      • 订单管理
      • 余额管理
      • 发票管理
      • 充值汇款
      • 续费管理
      快速入口
      • 天翼云旗舰店
      • 文档中心
      • 最新活动
      • 免费试用
      • 信任中心
      • 天翼云学堂
      云网生态
      • 甄选商城
      • 渠道合作
      • 云市场合作
      了解天翼云
      • 关于天翼云
      • 天翼云APP
      • 服务案例
      • 新闻资讯
      • 联系我们
      热门产品
      • 云电脑
      • 弹性云主机
      • 云电脑政企版
      • 天翼云手机
      • 云数据库
      • 对象存储
      • 云硬盘
      • Web应用防火墙
      • 服务器安全卫士
      • CDN加速
      热门推荐
      • 云服务备份
      • 边缘安全加速平台
      • 全站加速
      • 安全加速
      • 云服务器
      • 云主机
      • 智能边缘云
      • 应用编排服务
      • 微服务引擎
      • 共享流量包
      更多推荐
      • web应用防火墙
      • 密钥管理
      • 等保咨询
      • 安全专区
      • 应用运维管理
      • 云日志服务
      • 文档数据库服务
      • 云搜索服务
      • 数据湖探索
      • 数据仓库服务
      友情链接
      • 中国电信集团
      • 189邮箱
      • 天翼企业云盘
      • 天翼云盘
      ©2025 天翼云科技有限公司版权所有 增值电信业务经营许可证A2.B1.B2-20090001
      公司地址:北京市东城区青龙胡同甲1号、3号2幢2层205-32室
      • 用户协议
      • 隐私政策
      • 个人信息保护
      • 法律声明
      备案 京公网安备11010802043424号 京ICP备 2021034386号