Method: EZMQ::Socket#initialize

Defined in:
lib/ezmq/socket.rb

#initialize(mode, type, **options) ⇒ Socket

Note:

port is ignored unless transport is one of :tcp, :pgm or :epgm

Creates a 0MQ socket.

Parameters:

  • mode (:bind, :connect)

    the mode of the socket.

  • type (Object)

    the type of socket to use.

  • options (Hash)

    optional parameters.

Options Hash (**options):

  • context (ZMQ::Context)

    a context to use for this socket (one will be created if not provided).

  • encode (lambda)

    how to encode messages.

  • decode (lambda)

    how to decode messages.

  • transport (Symbol) — default: :tcp

    transport for transport.

  • address (String) — default: '127.0.0.1'

    address for endpoint.

  • port (Fixnum) — default: 5555

    port for endpoint.



26
27
28
29
30
31
32
33
34
# File 'lib/ezmq/socket.rb', line 26

def initialize(mode, type, **options)
  fail ArgumentError unless %i(bind connect).include? mode
  @context = options[:context] || EZMQ::Context.new
  @socket = @context.socket type
  @encode = options[:encode] || -> m { m }
  @decode = options[:decode] || -> m { m }
  endpoint = options.select { |k, _| %i(transport address port).include? k }
  method(mode).call endpoint
end