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

#initialize(mode = :bind, **options) ⇒ Server

Creates a new Server socket.

Parameters:

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

    (:bind) a mode for the socket.

  • options (Hash)

    optional parameters

See Also:



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

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

Instance Method Details

#listen {|message| ... } ⇒ void

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