简体   繁体   English

是否可以识别收到的网络套接字请求?

[英]Is it possible to identify web-socket request on receive?

I have two queries that are sent one after the other. 我有两个查询,一个接一个地发送。 If I use send method, than I get the response in onmessage and I need to know which response it was - from the first query or from the second. 如果我使用send方法,那么我会onmessage的响应,我需要知道它是哪个响应-从第一个查询或从第二个查询。 Is it possible? 可能吗?

You should add a correlation id to each request, and return that id with the response, that way the client would know which response is associated with which request. 您应该为每个请求添加一个关联ID,并在响应中返回该ID,这样客户端就可以知道哪个响应与哪个请求相关联。

Since it is a client concern, the id can be a simple incremental integer, does not need to be a GUID or unique number. 由于是客户问题,所以id可以是简单的增量整数,而不必是GUID或唯一编号。 The server just have to attach the request id to the response, does not need to do anything with it. 服务器只需要将请求ID附加到响应即可,而无需执行任何操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在没有 web-socket 的情况下从服务器监听事件 - How to listen the event from server without web-socket 通过网络套接字接收数据时 Blob 获取的问题 - Problems with Blob acquisition when receiving data through a web-socket 为什么尝试建立网络套接字时连接被拒绝? - Why is connection refused when trying to establish a web-socket? 如何为“ws”Web-Socket 模块创建自定义事件? - How to create custom events for 'ws' Web-Socket module? 识别Web套接字客户端 - Identify web socket client 如何使用来自网络套接字的网络音频 API 流式传输音频块? - how to stream audio chunks using web audio API coming from web-socket? 如何将网络套接字对象从我的服务同步到组件-angular 2 - How do i sync a web-socket object from my service to the component -angular 2 Web套接字可用于约8KB的小文件。 但是对于〜50KB的文件,我的连接断开了 - Web-socket worked for small files of ~8KB. But for ~50KB file, my connection disconnects Javascript 将用户名的每个部分添加到关键字数组以进行 Web 套接字查询? - Javascript add each part of username to keywords array for web-socket queries? 为什么消费者.py中的事件处理程序function被多次调用,然后web-socket连接被强制终止? - Why an event handler function in consumers.py is called multiple times and then web-socket connection is killed forcefully?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM