jwchang
jwchang

Reputation: 10864

Scaling Socket.IO and broadcast to all belonging clients

I'm using

Express with "connect-redis" session store

And I tied it with Socket.IO through configuring "authorization"

So that I don't have to actually use

socket.get

Or

socket.set

To store and retrieve a client's belonging variables.

But I'm not sure that If I broadcast a message to specific group of people, connected in different server, get message successfully.

So that it is truly scaled!

But It seems to be not truly scaled but only use Redis as storing values individually.

Also I tried to use

RedisStore

which is given by Socket.IO

does not work.

It is saying

DEBUG: TypeError: Converting circular structure to JSON
    at Redis.stringify [as pack] (native)
    at Redis.publish (/var/www/node_modules/socket.io/lib/stores/redis.js:106:31)
    at Manager.handleClient (/var/www/node_modules/socket.io/lib/manager.js:646:18)
    at Manager.handleHTTPRequest (/var/www/node_modules/socket.io/lib/manager.js:595:8)
    at Manager.handleRequest (/var/www/node_modules/socket.io/lib/manager.js:557:12)
    at HTTPServer.<anonymous> (/var/www/node_modules/socket.io/lib/manager.js:112:10)
    at HTTPServer.emit (events.js:70:17)
    at HTTPParser.onIncoming (http.js:1507:12)
    at HTTPParser.onHeadersComplete (http.js:102:31)
    at Socket.ondata (http.js:1403:22)

How can I scale Socket.IO with broadcasting to all scaled clients available?

Edit: I followed the Express-Session-Socket.IO tutorial and I have found that io.authorization actually makes problem but it is okay without io.authorization. How is that?

Upvotes: 2

Views: 1492

Answers (1)

elranu
elranu

Reputation: 2312

Socket.IO has his own authorization. It authorize for each socket. To customize the socket.IO Auth, using my code, write inside the io.configure function:

io.set('authorization', function (handshakeData, callback) {
       //your auth logic 
});

With my example RedisStore you scale to all bradcasting clients available.

Upvotes: 2

Related Questions