class Fleyhe::Network::Bridge
Made a bridge (Server <-> Client) in TCP to call Events
Public Class Methods
new(tcp, event=Event)
click to toggle source
# File lib/Fleyhe.rb, line 53 def initialize tcp, event=Event @tcp = tcp @event = event @thread = Thread.new { self.work } end
Public Instance Methods
call(event="Event",args=[])
click to toggle source
# File lib/Fleyhe.rb, line 67 def call event="Event",args=[] @tcp.puts event.to_s @tcp.puts args.size.to_s for i in args @tcp.puts i.to_s end end
close()
click to toggle source
# File lib/Fleyhe.rb, line 61 def close # Close your work @tcp.close @thread.kill end
read()
click to toggle source
# File lib/Fleyhe.rb, line 77 def read event = nil args = [] event = @tcp.gets.to_s.chomp n = @tcp.gets.to_i n.times do args << @tcp.gets.to_s end return event,args end
Protected Instance Methods
work()
click to toggle source
# File lib/Fleyhe.rb, line 94 def work begin loop { event = nil args = [] Timeout.timeout(60) {event, args = self.read} @event.getHash[event].new(self,args) } rescue => e puts "Error on Bridge: #{ self.to_s }" puts " \t #{ e.to_s }" self.close end end