I want to record socket.io message history, i.e. the contents of two users talked, for later use. Is there some socket.io built-in functions to realize this, or if not, what is a good way to realize it?
相关问题
- Multiple sockets for clients to connect to
- Netty websocket client does not read new frames fr
- Drakma and Dexador both fails at USocket call whil
- difference between file descriptor and socket file
- Django & node.js : throw arguments[1]; // Unhandle
相关文章
- 关于SignalR的问题
- MVC 中如何连接websocket?
- websocket 每60s报WsHttpUpgradeHandler.timeoutAsync
- websocket定时报超时错误
- Observatory server failed to start - Fails to crea
- Angular CLI: Proxy websocket with proxy.conf.json
- Streaming music synchronously from a mp3 file via
- why is socket.id undefined in the browser
First of, you need some way to identify the users with a unique id that does not disappear when the user disconnects, like a username or an email address.
All the messages in the conversation should then somehow be stored on the server, like in a "chat-object" for the conversation between the two users.
Either periodically, when the user disconnects, or every time a the "chat-object" changes (eg. a new message is sent), save the "chat-object" in a database of any sort you like. You can use JSON to serialize the "chat-object", save it in any way you like (eg. a custom file, a mysql database, or whatever). To serialize an object, use the code below on the node server:
Save the string together with the two users' unique IDs. So when a new conversation is started between the same two people. You can just go to your file or database and retrieve the old chatobject, and unserialize it with the following code.