admin管理员组文章数量:1335356
Lets say that i make a websocket server chat (node.js + socket.io). How would i store the chat messages, so that when a "new" user joins the chat, he will be seeing old chat messages, and not just the ones which has been sent while hes in the chat.
Should the data be stored in variables in the server? Something like:
var io = require('socket.io').listen(80);
var saveData = { };
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
Would it be a viable soultion for a more plex application, like a game for example?
Thanks
Lets say that i make a websocket server chat (node.js + socket.io). How would i store the chat messages, so that when a "new" user joins the chat, he will be seeing old chat messages, and not just the ones which has been sent while hes in the chat.
Should the data be stored in variables in the server? Something like:
var io = require('socket.io').listen(80);
var saveData = { };
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
Would it be a viable soultion for a more plex application, like a game for example?
Thanks
Share Improve this question asked Aug 13, 2012 at 18:17 JohanJohan 35.2k62 gold badges187 silver badges305 bronze badges2 Answers
Reset to default 3If you really need to store chat history for new user I would suggest storing those in RDBMS or NoSQL storage. If you choose NoSQL one of options is Apache CouchDB™ (database that uses JSON for documents, JavaScript for MapReduce queries, and regular HTTP for an API). Here is free online book about it.
Have a look at redis (redis.io), an in-memory database (disk persistent). Real fast, and your data will persist across server restarts. It also plays really really well with node.js.
本文标签: javascriptwebsocket serverstoring the dataStack Overflow
版权声明:本文标题:javascript - websocket server, storing the data - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742370061a2462059.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论