Sha256: 5004043f74259b0ad6d28113c9c5ea9bd3259c52675333ca8b44817e001fb273
Contents?: true
Size: 1.05 KB
Versions: 5
Compression:
Stored size: 1.05 KB
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 [:bind, :connect] mode (:bind) a mode for the socket. # @param [Hash] options optional parameters # @see EZMQ::Socket EZMQ::Socket for optional parameters. # # @return [Server] a new instance of Server # def initialize(mode = :bind, **options) super mode, 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
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
ezmq-0.4.12 | lib/ezmq/reply.rb |
ezmq-0.4.11 | lib/ezmq/reply.rb |
ezmq-0.4.4 | lib/ezmq/reply.rb |
ezmq-0.4.3 | lib/ezmq/reply.rb |
ezmq-0.4.2 | lib/ezmq/reply.rb |