Class: MaZMQ::Reply

Inherits:
SocketHandler show all
Defined in:
lib/ma-zmq/reply.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from SocketHandler

#addresses, #bind, #close, #connect, #identity, #identity=, #on_read, #on_write, #socket_type

Constructor Details

#initializeReply

Returns a new instance of Reply.



5
6
7
8
# File 'lib/ma-zmq/reply.rb', line 5

def initialize
  @socket_type = ZMQ::REP
  super
end

Instance Attribute Details

#stateObject (readonly)

Returns the value of attribute state.



3
4
5
# File 'lib/ma-zmq/reply.rb', line 3

def state
  @state
end

Instance Method Details

#recv_stringObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ma-zmq/reply.rb', line 10

def recv_string
  case @state
    when :idle
      msg = super
      if msg and not msg.empty?
        @state = :reply
      end
      return msg
    else
      return false
  end
end

#send_string(msg) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/ma-zmq/reply.rb', line 23

def send_string(msg)
  case @state
    when :reply
      resp = super(msg)
      @state = :idle
      return resp
    else
      return false
  end
end