Class: EZMQ::Server

Inherits:
Socket show all
Defined in:
lib/ezmq/reply.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

#connect, #receive, #send

Constructor Details

- (Server) initialize(**options)

Creates a new Server socket.

Parameters:

  • options (Hash)

    optional parameters

See Also:



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

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.



29
30
31
32
33
34
35
36
37
# File 'lib/ezmq/reply.rb', line 29

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