Fix timeout on connections

This commit is contained in:
Cryptkeeper
2015-11-02 00:01:04 -06:00
parent dec1536c6c
commit 0cbfcf60d7
4 changed files with 11 additions and 7 deletions

View File

@ -8,8 +8,8 @@ winston.add(winston.transports.File, {
winston.add(winston.transports.Console, {
'timestamp': function() {
var date = new Date();
return date.toLocaleTimeString() + " " + date.getDate() + "/" + (date.getMonth() + 1) + "/" + date.getFullYear().toString().substring(2, 4);
return date.toLocaleTimeString() + ' ' + date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear().toString().substring(2, 4);
},
'colorize': true
});

View File

@ -5,6 +5,12 @@ function pingMinecraftPC(host, port, timeout, callback) {
var client = new net.Socket();
var milliseconds = (new Date).getTime();
client.setTimeout(timeout, function() {
client.destroy();
callback(new Error('timeout'), null);
});
client.connect(port, host, function() {
// Write out handshake packet.
var handshakeBuffer = mcpc.createBuffer();
@ -69,11 +75,6 @@ function pingMinecraftPC(host, port, timeout, callback) {
client.on('error', function(err) {
callback(err, null);
});
// Make sure we don't go overtime.
setTimeout(function() {
client.end();
}, timeout);
}
// Wraps our Buffer into another to fit the Minecraft protocol.