Module: Rum::Remote::Connection::Messaging

Defined in:
lib/rum/remote.rb

Instance Method Summary collapse

Instance Method Details

#dispatch(msg) ⇒ Object

Assumes message is not larger than 4,3 GB ((2**(4*8) - 1) bytes)



29
30
31
32
33
# File 'lib/rum/remote.rb', line 29

def dispatch(msg)
  msg.encode! Encoding::UTF_8
  msg.force_encoding Encoding::BINARY
  write([msg.length].pack('N') + msg)
end

#receiveObject



35
36
37
38
39
40
# File 'lib/rum/remote.rb', line 35

def receive
  if message_size = read(4) # sizeof (N)
    message_size = message_size.unpack('N')[0]
    read(message_size).force_encoding(Encoding::UTF_8)
  end
end