Sha256: 13ea2862a6160b8020a3f244d7181471ff453d4184683ddc9a9a94bc94279aac

Contents?: true

Size: 997 Bytes

Versions: 9

Compression:

Stored size: 997 Bytes

Contents

require_relative 'socket'

# Syntactic sugar for 0MQ, because Ruby shouldn't feel like C.
module EZMQ
  # Reply socket that listens for and replies to requests.
  class Server < EZMQ::Socket
    # Creates a new Server socket.
    #
    # @param [Hash] options optional parameters
    #
    # @see EZMQ::Socket EZMQ::Socket for optional parameters.
    #
    # @return [Server] a new instance of Server
    #
    def initialize(**options)
      super :bind, ZMQ::REP, options
    end

    # Listens for a request, and responds to it.
    #
    # If no block is given, responds with the request message.
    #
    # @yield message passes the message received to the block.
    # @yieldparam [String] message the message received.
    # @yieldreturn [void] the message to reply with.
    #
    # @return [void] the return from handler.
    #
    def listen
      loop do
        if block_given?
          send yield receive
        else
          send receive
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ezmq-0.4.1 lib/ezmq/reply.rb
ezmq-0.4.0 lib/ezmq/reply.rb
ezmq-0.3.7 lib/ezmq/reply.rb
ezmq-0.3.6 lib/ezmq/reply.rb
ezmq-0.3.5 lib/ezmq/reply.rb
ezmq-0.3.4 lib/ezmq/reply.rb
ezmq-0.3.3 lib/ezmq/reply.rb
ezmq-0.3.2 lib/ezmq/reply.rb
ezmq-0.3.1 lib/ezmq/reply.rb