Class: Rubtella::Listener
- Inherits:
-
Object
- Object
- Rubtella::Listener
- Includes:
- Socket::Constants
- Defined in:
- lib/rubtella/rubtella.rb
Instance Method Summary collapse
-
#listen ⇒ Object
listen for connection.
- #manage_connection(stream) ⇒ Object
Instance Method Details
#listen ⇒ Object
listen for connection
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rubtella/rubtella.rb', line 24 def listen server = TCPServer.new("0.0.0.0", PORT) while (session = server.accept) Thread.start do begin manage_connection session rescue => e session.puts "Rubtella Listener Error: " + e.to_s @@logger.info "Rubtella Server Error: " + e.to_s ensure session.close end end end #end loop end |
#manage_connection(stream) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rubtella/rubtella.rb', line 46 def manage_connection stream loop do @@logger.info 'we\'re listening..' resp = stream.recv 1000 if parse(resp) == "ping" pong = TCPData::Builder::Pong.new stream.send pong.build , 0 @@logger.info 'pong send..' stream.close @@logger.info 'connection closed' break end end end |