1

I am creating a chat server with nodejs and mongo as a demo. I have it where each user can send another authenticated user a message. What I am trying to do now is make is scalable.

My Idea is to save the sockets inside MongoDB and then have several node servers running that check to see if that user is online in the DB, if so, send the message to that socket.

Although when I try to store the socket in the DB via JSON.Stringify into a type:String, it gives me an error: 'Exception in cluster master process: Converting circular structure to JSON'

Any help would be great!

Thanks,

Quinton Pike
  • 3,823
  • 8
  • 31
  • 37
  • 1
    It is not a good idea, since your `socket` is not actually a piece of Document or Data. Also, I don't see a way to store it inside MongoDB. – Felix Yan Dec 19 '11 at 16:37
  • What would be the best solution to making it scalable? – Quinton Pike Dec 19 '11 at 16:37
  • Why not just use a popular protocol and server module, such as XMPP? – Felix Yan Dec 19 '11 at 16:40
  • I was very brief about the summary of the project, but it will be going on a gaming site that gets millions of pageviews a day. It will be a little more complex than just a chat server, but I didnt want to flood the question with what the apps going to do, basically I cant seem to find a good solution to saving sockets globally for multiple servers to check. – Quinton Pike Dec 19 '11 at 16:42
  • qrpike, RedisStore is exactly for that purpose. Implementing it even caused a major rewrite for Socket.IO this year :) – alessioalex Dec 19 '11 at 19:29

1 Answers1

0

If you want to scale you Socket.IO file, Redis is the way to do it, namely using RedisStore, check the following resources:

How can I scale socket.io?
https://github.com/dshaw/talks/tree/master/2011-10-jsclub
http://www.danielbaulig.de/socket-ioexpress/

Community
  • 1
  • 1
alessioalex
  • 62,577
  • 16
  • 155
  • 122