Home
Ratchet Library :: API Reference
API  ·  Manual

Module ratchet.zmqsocket

The zmqsocket library provides an implementation of the ZeroMQ socket library on top of the ratchet library. Any methods that pause execution MUST be called from within a thread attached to a ratchet object. These functions can fail, see error handling section in manual for details.

Functions

bind (self, endpoint) Binds the socket to the given endpoint and accepts connections.
connect (self, endpoint) Connects the socket to the given endpoint.
get_fd (self) Returns the internal socket file descriptor.
get_timeout (self) Gets the current timeout for all methods that pause the thread.
new (type) Returns a new zmqsocket object.
prepare_uri (uri) URI schema handler for TCP connection strings.
recv (self) Pauses the current thread until the socket has data to receive and returns it.
recv_all (self) Loops calls to recv() until all message parts are received.
send (self, data, more_coming) Pauses the current thread until the socket is ready to send data and then sends it.
set_timeout (self, seconds) Sets the current timeout for all methods that pause the thread.


Functions

bind (self, endpoint)
Binds the socket to the given endpoint and accepts connections.

Parameters

  • self: the zmqsocket object.
  • endpoint: connection string to bind to.
connect (self, endpoint)
Connects the socket to the given endpoint.

Parameters

  • self: the zmqsocket object.
  • endpoint: connection string to connect to.
get_fd (self)
Returns the internal socket file descriptor.

Parameters

  • self: the zmqsocket object.

Return value:

a file descriptor.
get_timeout (self)
Gets the current timeout for all methods that pause the thread.

Parameters

  • self: the zmqsocket object.

Return value:

the current timeout in seconds.
new (type)
Returns a new zmqsocket object.

Parameters

  • type: string corresponding to ZeroMQ socket types, e.g. "PAIR".

Return value:

a new zmqsocket object.
prepare_uri (uri)
URI schema handler for TCP connection strings. Strings must with "zmq", followed by a ":", followed by a ZeroMQ socket type (e.g. "PAIR"), followed by a ":", followed by something suitable to be passed to zmq_connect() or zmq_bind() as an endpoint. See the manual page for complete details.

Parameters

  • uri: the URI connection string.

Return value:

table containing keys "type" and "endpoint" useful in creation and usage of zmqsocket objects.
recv (self)
Pauses the current thread until the socket has data to receive and returns it. This call only receives one message part, but tells if this message has more parts to follow.

Parameters

  • self: the zmqsocket object.

Return value:

string containing data, followed by true if there are more parts of this message to receive.
recv_all (self)
Loops calls to recv() until all message parts are received. Message parts are concatenated into one large string.

Parameters

  • self: the zmqsocket object.

Return value:

string containing the data.
send (self, data, more_coming)
Pauses the current thread until the socket is ready to send data and then sends it.

Parameters

  • self: the zmqsocket object.
  • data: string with the data to send.
  • more_coming: optionally pass true if more message parts will be sent, last message part more_coming must be false or not given.
set_timeout (self, seconds)
Sets the current timeout for all methods that pause the thread.

Parameters

  • self: the zmqsocket object.
  • seconds: the new timeout in seconds.