Module: EventMachine::Protocols::LineProtocol

Defined in:
lib/em/protocols/line_protocol.rb

Overview

LineProtocol will parse out newline terminated strings from a receive_data stream

module Server
  include EM::P::LineProtocol

  def receive_line(line)
    send_data("you said: #{line}")
  end
end

Instance Method Summary collapse

Instance Method Details

#receive_data(data) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/em/protocols/line_protocol.rb', line 15

def receive_data data
  (@buf ||= '') << data

  @buf.each_line do |line|
    if line[-1] == "\n"
      receive_line(line.chomp)
    else
      @buf = line
    end
  end
end

#receive_line(line) ⇒ Object

Invoked with lines received over the network



28
29
30
# File 'lib/em/protocols/line_protocol.rb', line 28

def receive_line(line)
  # stub
end