Class: EZMQ::Client

Inherits:
Socket show all
Defined in:
lib/ezmq/request.rb

Overview

Request socket that sends messages and receives replies.

Instance Attribute Summary

Attributes inherited from Socket

#context, #decode, #encode, #socket

Instance Method Summary collapse

Methods inherited from Socket

#connect, #listen, #receive, #send

Constructor Details

#initialize(mode = :connect, **options) ⇒ Client

Creates a new Client socket.

Parameters:

  • mode (:bind, :connect) (defaults to: :connect)

    (:connect) a mode for the socket.

  • options (Hash)

    optional parameters.

See Also:



15
16
17
# File 'lib/ezmq/request.rb', line 15

def initialize(mode = :connect, **options)
  super mode, ZMQ::REQ, options
end

Instance Method Details

#request(message, **options) ⇒ void

This method returns an undefined value.

Sends a message and waits to receive a response.

Parameters:

  • message (String)

    the message to send.

  • options (Hash)

    optional parameters.

Options Hash (**options):

  • encode (lambda)

    how to encode the message.

  • decode (lambda)

    how to decode the message.



28
29
30
31
32
33
34
35
# File 'lib/ezmq/request.rb', line 28

def request(message, **options)
  send message, options
  if block_given?
    yield receive options
  else
    receive options
  end
end