[英]How to send old messages with Websockets
I've got a working Websockets example, where clients receive messages from the server. 我有一个工作的Websockets示例,客户端从服务器接收消息。
I'm not sure how I should send old messages to clients when they connect. 我不确定如何在连接时向客户端发送旧消息。
Example: 例:
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). 我想知道客户是否有任何方式可以接收旧消息(无论是全部消息,还是最近5分钟内的消息都可以接受)。
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 因此,您必须编写代码以向用户广播数据
By the way what are you using server side? 那么你使用服务器端的方式是什么? (Node, Erlang , etc) (节点,Erlang等)
You can check following link if you are using node.js 如果您使用node.js,可以检查以下链接
http://martinsikora.com/nodejs-and-websocket-simple-chat-tutorial http://martinsikora.com/nodejs-and-websocket-simple-chat-tutorial
You could do something like this: 你可以这样做:
Hope it helps 希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.