Set no delay on stream if it's TCP. Fixes #38

This commit is contained in:
roblabla 2014-10-29 00:30:33 +01:00
parent 33e9c39af6
commit baaac91055

View file

@ -75,6 +75,8 @@ Client.prototype.onRaw = function(type, func) {
Client.prototype.setSocket = function(socket) { Client.prototype.setSocket = function(socket) {
var self = this; var self = this;
self.socket = socket; self.socket = socket;
if (self.socket.setNoDelay)
self.socket.setNoDelay(true);
var incomingBuffer = new Buffer(0); var incomingBuffer = new Buffer(0);
self.socket.on('data', function(data) { self.socket.on('data', function(data) {
if (self.encryptionEnabled) data = new Buffer(self.decipher.update(data), 'binary'); if (self.encryptionEnabled) data = new Buffer(self.decipher.update(data), 'binary');
@ -128,7 +130,7 @@ Client.prototype.connect = function(port, host) {
var self = this; var self = this;
if (port == 25565) { if (port == 25565) {
dns.resolveSrv("_minecraft._tcp." + host, function(err, addresses) { 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)); self.setSocket(net.connect(addresses[0].port, addresses[0].name));
} else { } else {
self.setSocket(net.connect(port, host)); self.setSocket(net.connect(port, host));
@ -150,7 +152,7 @@ Client.prototype.write = function(packetId, params) {
return false; return false;
packetId = packetId[1]; packetId = packetId[1];
} }
var buffer = createPacketBuffer(packetId, this.state, params, this.isServer); var buffer = createPacketBuffer(packetId, this.state, params, this.isServer);
debug("writing packetId " + packetId + " (0x" + packetId.toString(16) + ")"); debug("writing packetId " + packetId + " (0x" + packetId.toString(16) + ")");
debug(params); 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; var out = (shouldEncrypt && this.encryptionEnabled) ? new Buffer(this.cipher.update(buffer), 'binary') : buffer;
this.socket.write(out); this.socket.write(out);
}; };