Class: EZMQ::Server

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

Overview

Reply socket that listens for and replies to requests.

Instance Attribute Summary

Attributes inherited from Socket

#context, #decode, #encode, #socket

Instance Method Summary (collapse)

Methods inherited from Socket

#bind, #connect, #receive, #send

Constructor Details

- (Server) initialize(**options)

Creates a new Server socket.

Parameters:

  • options (Hash)

    optional parameters

See Also:



166
167
168
# File 'lib/ezmq.rb', line 166

def initialize(**options)
  super :bind, ZMQ::REP, options
end

Instance Method Details

- (void) listen {|message| ... }

This method returns an undefined value.

Listens for a request, and responds to it.

If no block is given, responds with the request message.

Yields:

  • message passes the message received to the block.

Yield Parameters:

  • message (String)

    the message received.

Yield Returns:

  • (void)

    the message to reply with.



180
181
182
183
184
185
186
187
188
# File 'lib/ezmq.rb', line 180

def listen
  loop do
    if block_given?
      send yield receive
    else
      send receive
    end
  end
end