diff --git a/lib/client.js b/lib/client.js index e784b87..e6315fe 100644 --- a/lib/client.js +++ b/lib/client.js @@ -142,8 +142,14 @@ var Client = exports.Client = function Client (port, host, options) { this.connectionsMade = 0; - // Setup the TCP connection - var stream = this.stream = net.createConnection(this.port = port, this.host = host); + if (port === 0) { + // Assume UNIX socket, take host as path to socket file + this.port = port; + var stream = this.stream = net.createConnection(this.host = host); + } else { + // Regular TCP socket, setup the TCP connection + var stream = this.stream = net.createConnection(this.port = port, this.host = host); + } stream.on("data", this.handleData.bind(this)); // currReply = null; @@ -336,7 +342,11 @@ Client.prototype.attemptReconnect = function () { client = this; this.reconnectionTimer = setTimeout( function () { client.emit("reconnecting", client); - stream.connect(client.port, client.host); + if (client.port === 0) { // UNIX socket + stream.connect(client.host); + } else { // TCP socket + stream.connect(client.port, client.host); + } }, delay); };