Fix timeout on connections
This commit is contained in:
parent
dec1536c6c
commit
0cbfcf60d7
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
node_modules/
|
||||
*.log
|
2
app.js
2
app.js
@ -70,6 +70,8 @@ server.start(function() {
|
||||
// Attach our listeners.
|
||||
client.on('disconnect', function(client) {
|
||||
connectedClients -= 1;
|
||||
|
||||
logger.log('info', 'Client disconnected, total clients: %d', connectedClients);
|
||||
});
|
||||
});
|
||||
});
|
@ -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
|
||||
});
|
||||
|
11
lib/ping.js
11
lib/ping.js
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user