Method: Reader::JSTP::Engine#tcp
- Defined in:
- lib/reader/jstp/engine.rb
#tcp ⇒ Object
Start the server with the TCP strategy
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/reader/jstp/engine.rb', line 41 def tcp @server = TCPServer.new @config.port.inbound @config.logger.info "JSTP node running on TCP mode in #{@config.hostname}:#{@config.port.inbound}" loop { Thread.start(@server.accept) { |client| begin # Opening routine token = UUID.new.generate @source.clients[token] = client if @source.respond_to? :open begin @source.open client, token rescue Exception => e @config.logger.error "On open hook: #{e.class}: #{e.message}" @config.logger.debug e.backtrace.to_s end end # Message loop while line = client.gets begin = ::JSTP::Dispatch.new line @source.dispatch , client rescue Exception => e log_exception e, end end # Closing routine client.close @source.clients.delete token if @source.respond_to? :close @source.close client, token end rescue Exception => exception @config.logger.error "Client #{token} is DOWN: #{exception.class}: #{exception.message}" @config.logger.debug exception.backtrace.to_s client.close end } } rescue Exception => e @config.logger.fatal "Could not initialize TCP server on port #{@config.port.inbound}" end |