Module: SocketMessage

Defined in:
lib/minitcp.rb

Overview

messages stream

Instance Method Summary collapse

Instance Method Details

#on_message(timeout = nil, &b) ⇒ Object


347
348
349
350
351
352
353
354
355
# File 'lib/minitcp.rb', line 347

def on_message(timeout=nil,&b)
on_n_receive(6) do |head| 
	len=head.to_i
	received_n_timeout(len,10_000) do |data|
		response=b.call(eval(data))
		send(response) if response
	end
 end
end

#send_message(message) ⇒ Object


356
357
358
359
# File 'lib/minitcp.rb', line 356

def send_message(message)
	data=message.inspect
	send(("%6d" % data.size)+data,0)		
end