在socket.io中的消息排序 [英] Message ordering in socket.io

查看:85
本文介绍了在socket.io中的消息排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

socket.io是否保证以与发出消息相同的顺序调用on()回调?

Does socket.io guarantee that on() callbacks will be called in the same order that the messages were emitted?

推荐答案

Node.js是单个事件循环,所以可以.

Node.js is a single event loop so yes.

但是您还有另一个问题,请考虑一下您和客户端之间的延迟,如果两个客户端发送了消息,则将首先处理到达服务器的第一条消息,因此,如果第一个客户端发出了他的消息,但他有第二个客户端(在第一个客户端之后发送了他的消息)对服务器的等待时间较长,那么很可能是第二个客户端消息将首先被处理

But you have another problem, think about the latency between you and your clients, if two clients sent their messages, the first message that came to the server will be handled first, so if the first client emitted his message but he had a higher latency to the server from the second client (which sent his message after the first client), then it's probably be the second client message that will be handled first

这篇关于在socket.io中的消息排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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