WebSocket 请求-响应子协议 [英] WebSocket request-response subprotocol

查看:67
本文介绍了WebSocket 请求-响应子协议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WebSocket 提供了一种双向通信,就像人说话一样.客户端可以向服务器发送数据,服务器可以随时向客户端发送数据.但是请求-响应行为呢?客户端可以向服务器询问一些事情并等待响应.似乎 Websocket 没有提供任何将客户端数据(请求)链接到服务器数据(响应)的东西.

WebSocket provides a bi-directional communication like a human being talks. The client can send data to the server and the server can send data to the client anytime. But what about the request-response behavior? The client could ask something to the server and wait for a response. It seems that Websocket doesn't provide anything to link client data (request) to server data (response).

这可能是子协议的工作,我有一些关于如何做的想法(发送带有请求的 ID 并在超时时间内等待具有相同 ID 的响应).

It's probably the work of the subprotocol and I have some ideas on how to do it (send an ID with the request and wait for a reponse with the same ID within a timeout period).

为了不重新发明轮子并节省一些时间,我在互联网上查找了现有的解决方案,但我没有找到任何相关的内容(可能是不好的关键字).

In order to not reinvent the wheel and to save some time, I looked over the internet for an existing solution but I haven't found anything related (maybe bad keywords).

那么,有没有人知道这种工作,或者我错过了什么?

So, is there anyone aware about this kind of work or am I missing something?

推荐答案

WebSocket 应用消息传递协议 (WAMP) https://wamp-proto.org/ 为此目的在原始 WebSocket 之上提供了 RPC(远程过程调用)和 PubSub(发布和订阅)消息传递模式.

The WebSocket Application Messaging Protocol (WAMP) https://wamp-proto.org/ provides RPC (Remote Procedure Call) and PubSub (Publish & Subscribe) messaging patterns on top of raw WebSocket for that purpose.

WAMP 是一个合适的 WebSocket 子协议,使用 WebSocket 作为传输和 JSON 作为有效负载格式.RPC 使用 3 条消息实现,这些消息包含一个呼叫 ID";将异步 RPC 服务器响应与客户端发起的过程调用相关联.

WAMP is a proper WebSocket subprotocol, uses WebSocket as transport and JSON as a payload format. RPC is implemented using 3 messages, and those messages contain a "Call ID" to correlate asynchronous RPC server responses to client initiated procedure calls.

免责声明:我是 WAMP 和一些(开源)WAMP 实现的作者.这是一个开放的倡议,其他人已经开始上船.最终,应该有一个 WAMP RFC 正确定义协议......但它仍处于早期阶段.

Disclaimer: I am author of WAMP and some (open-source) WAMP implementations. Its an open initiative, with others already started to get on the boat. Ultimately, there should be a WAMP RFC properly defining the protocol .. but its still in the early stages.

这篇关于WebSocket 请求-响应子协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆