Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ function Client(options) {
this._timeout = options.timeout || DEFAULT_TIMEOUT;
this._socket = socket.client(heartbeat);

util.eventProxy(this._socket, this, "error");
this._socket.setTimeout(this._timeout)

util.eventProxy(this._socket, this, "error");
util.eventProxy(this._socket, this, "connect");
util.eventProxy(this._socket, this, "disconnect");
util.eventProxy(this._socket, this, "close");
}

nodeUtil.inherits(Client, events.EventEmitter);
Expand Down
24 changes: 24 additions & 0 deletions lib/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,29 @@ Socket.prototype.bind = function(endpoint) {
//endpoint : String
// The ZeroMQ endpoint
Socket.prototype.connect = function(endpoint) {
var self = this
this._zmqSocket.on('connect', function () {
this.connected = true
self.emit('connect')
})

this._zmqSocket.on('disconnect', function () {
this.connected = false
self.emit('disconnect')
})

this._zmqSocket.on('close', function () {
this.connected = false
self.emit('close')
})
this._zmqSocket.monitor(500, 0)
setTimeout(function() {
self._zmqSocket.unmonitor();
if(!self.connected) {
self.emit('disconnect')
}
}, (this.timeout || DEFAULT_TIMEOUT) * 1000); //30 seconds to connect

this._zmqSocket.connect(endpoint);
}

Expand Down Expand Up @@ -146,6 +169,7 @@ MultiplexingSocket.prototype.closed = function() {
};

MultiplexingSocket.prototype.setTimeout = function(timeout) {
this.timeout = timeout
};

//Creates a new multiplexing socket server
Expand Down