semico young
semico young

Reputation: 31

What does adapter means in socket.io

I am using socket.io these days, but I don't really understand what does adapter means in socket.io. Can anybody explain it to me? Thanks a lot!

Upvotes: 0

Views: 956

Answers (1)

Adiii
Adiii

Reputation: 60114

Socket.IO applications can be scaled out by using an adapter to distribute messages and events between multiple application instances. By running socket.io with the socket.io-redis adapter you can run multiple socket.io instances in different processes or servers that can all broadcast and emit events to and from each other.

Passing events between nodes

Now that you have multiple Socket.IO nodes accepting connections, if you want to broadcast events to everyone (or even everyone in a certain room) you’ll need some way of passing messages between processes or computers. The interface in charge of routing messages is what we call the Adapter. You can implement your own on top of the socket.io-adapter (by inheriting from it) or you can use the one we provide on top of Redis: socket.io-redis:

var io = require('socket.io')(3000);
var redis = require('socket.io-redis');
io.adapter(redis({ host: 'localhost', port: 6379 }));

Upvotes: 3

Related Questions