Created
May 8, 2014 08:04
-
-
Save dmitrijs-balcers/c1deabf852104fa6ad90 to your computer and use it in GitHub Desktop.
client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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