我开发了一个使用以下技术的JavaScript聊天(后端使用PHP):
1) long-polling to get new messages for the receiver
2) sessionStorage to store the counter of messages
3) setInterval to read new messages and if sessionStorageCounter < setIntervalCounter then the last message is shown to receiver.
4) javascript to create,update and write the chat dialogues
这个模块工作良好,但是当用户进行快速聊天时,接收方的前端会收到两到三条相同的消息(计数器不失败,查询也不提供双重插入)。
代码似乎正确(这就是为什么我不提供代码的原因),所以时间间隔延迟可能是原因(缩短时间间隔延迟并没有改变任何内容)。
您认为上述架构是不好的做法吗?您认为哪种架构可以消除这些错误?