Skip to content

Instantly share code, notes, and snippets.

@dmitrijs-balcers
Created May 8, 2014 08:04
Show Gist options
  • Save dmitrijs-balcers/c1deabf852104fa6ad90 to your computer and use it in GitHub Desktop.
Save dmitrijs-balcers/c1deabf852104fa6ad90 to your computer and use it in GitHub Desktop.
client
var net = require('net'),
config = require('../../../config');
var client = net.connect(
{
host: config.host,
port: config.port
},
function () {
log.trace('SH TCP socket connected');
client.write(requests.getServerInfo());
}
);
var log = require('../../../logger');
client.on('data', function (data) {
// Operate with data
});
client.on('error', function (err) {
log.error({ err: err, interval: 1000 }, 'error working with SH TCP socket; restarting');
setTimeout(function () {
// how can I reconnect to the socket?
}, 1000);
});
client.on('end', function () {
log.warn({ interval: 1000 }, 'SH TCP socket disconnected; restarting');
setTimeout(function () {
// how can I reconnect to the socket?
}, 1000);
});
module.exports.client = client;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment