Create a gist now

Instantly share code, notes, and snippets.

ActionHero Example Task: Ping Socket Clients
exports.task = {
name: 'pingSocketClients',
description: 'I will send a message to all connected socket clients. This will help with TCP keep-alive and send the current server time. Note that this will only ping the clients of one server, and will not work in cluster',
frequency: 5 * 1000,
queue: 'default',
plugins: [],
pluginOptions: {},
run: function(api, params, next){
for(var i in api.connections.connections){
var connection = api.connections.connections[i];
if(connection.type == 'socket'){
var message = {};
message.context = "api";
message.status = "keep-alive";
message.serverTime = new Date();
connection.sendMessage(message)
}
}
next();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment