From baaac91055ec855733235f1f074828fb4d113eea Mon Sep 17 00:00:00 2001 From: roblabla Date: Wed, 29 Oct 2014 00:30:33 +0100 Subject: [PATCH] Set no delay on stream if it's TCP. Fixes #38 --- lib/client.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/client.js b/lib/client.js index 1e19197..23d5576 100644 --- a/lib/client.js +++ b/lib/client.js @@ -75,6 +75,8 @@ Client.prototype.onRaw = function(type, func) { Client.prototype.setSocket = function(socket) { var self = this; self.socket = socket; + if (self.socket.setNoDelay) + self.socket.setNoDelay(true); var incomingBuffer = new Buffer(0); self.socket.on('data', function(data) { if (self.encryptionEnabled) data = new Buffer(self.decipher.update(data), 'binary'); @@ -128,7 +130,7 @@ Client.prototype.connect = function(port, host) { var self = this; if (port == 25565) { dns.resolveSrv("_minecraft._tcp." + host, function(err, addresses) { - if (addresses) { + if (addresses && addresses.length > 0) { self.setSocket(net.connect(addresses[0].port, addresses[0].name)); } else { self.setSocket(net.connect(port, host)); @@ -150,7 +152,7 @@ Client.prototype.write = function(packetId, params) { return false; packetId = packetId[1]; } - + var buffer = createPacketBuffer(packetId, this.state, params, this.isServer); debug("writing packetId " + packetId + " (0x" + packetId.toString(16) + ")"); debug(params); @@ -165,4 +167,4 @@ Client.prototype.writeRaw = function(buffer, shouldEncrypt) { } var out = (shouldEncrypt && this.encryptionEnabled) ? new Buffer(this.cipher.update(buffer), 'binary') : buffer; this.socket.write(out); -}; \ No newline at end of file +};