如何使用 Websockets 发送旧消息 [英] How to send old messages with Websockets

查看:20
本文介绍了如何使用 Websockets 发送旧消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可用的 Websockets 示例,其中客户端从服务器接收消息.

I've got a working Websockets example, where clients receive messages from the server.

我不确定应该如何在客户端连接时向他们发送旧消息.

I'm not sure how I should send old messages to clients when they connect.

示例:

  • 每个客户端在连接时提供他们的名字
  • 服务器响应[name] just connected"(对所有客户端)
  • 任何新客户都不会收到这些消息

我想知道客户是否可以通过任何方式接收旧消息(所有消息或过去 5 分钟内的消息都可以接受).

I'm wondering if there's any way clients can receive old messages (either all of them, or messages in the last 5 minutes would be acceptable).

我怀疑我可能必须自己捕获这些信息,将其存储在某个地方(如数据库)并自己将消息发送给新客户.是这样,还是我遗漏了什么?

I suspect I may have to capture this information myself, store it somewhere (like a database) and send the messages to new clients myself. Is that right, or am I missing something?

如果有人有伪代码,或者其他人如何实现这一点的示例的链接,那就很方便了.

If anyone has pseudo code, or a link to an example of how others have implemented this, that would be handy.

推荐答案

您必须自己捕获它并将其存储在服务器上...一旦用户连接,您必须将该数据命名为所有连接的客户端和您已存储回已连接的用户的消息.因此,您必须编写代码才能将数据广播给用户

You will have to capture it by your own and store it on server... once user connects you will have to name that data to all connected clients and the messages which you have stored back to the user who has connected. So, you will have to code to broadcast the data to users

顺便说一下,你在使用什么服务器端?(节点、Erlang 等)

By the way what are you using server side? (Node, Erlang , etc)

如果您使用的是 node.js,可以查看以下链接

You can check following link if you are using node.js

http://martinsikora.com/nodejs-and-websocket-simple-聊天教程

这篇关于如何使用 Websockets 发送旧消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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