def listen(self, factory): """ What servers do. This is Twisted-speak for "bind." For notes about the use of deferred here, see the deffered comment in the docstring for ZmqConnection.connect. """ try: self._connectOrBind(factory) except Exception, err: msg = util.buildErrorMessage(err) return defer.fail(exceptions.ListenError(msg))
def connect(self, factory): """ What clients do. The use of deferreds here is somewhat of an artiface, providing API similarity with Twisted code more than anything else. What's async in txZMQ is really the reactor checking the socket's file descriptor to see if there's data available to read or write. """ try: self._connectOrBind(factory) except Exception, err: msg = util.buildErrorMessage(err) return defer.fail(exceptions.ConnectionError(msg))
def unsubscribe(self, tag): """ Unsubscribe from messages with specified tag (prefix). For notes about the use of deferred here, see the deffered comment in the docstring for ZmqConnection.connect. @param tag: message tag @type tag: C{str} """ try: self.socket.setsockopt(constants.UNSUBSCRIBE, tag) except Exception, err: msg = util.buildErrorMessage(err) return defer.fail(exceptions.UnsubscribingError(msg))
def publish(self, message, tag=''): """ Broadcast L{message} with specified L{tag}. For notes about the use of deferred here, see the deffered comment in the docstring for ZmqConnection.connect. @param message: message data @type message: C{str} @param tag: message tag @type tag: C{str} """ try: self.send(tag + '\0' + message) except Exception, err: msg = util.buildErrorMessage(err) return defer.fail(exceptions.PublishingError(msg))