Class: SWS::Adaptor::Standalone
Overview
Adaptor listening on a TCPport
Constant Summary
Constants inherited from Generic
Instance Attribute Summary collapse
-
#port ⇒ Object
Returns the value of attribute port.
Attributes inherited from Generic
Instance Method Summary collapse
-
#each_request ⇒ Object
Main adaptor method - invokes block for each received request.
-
#initialize(port = 1234) ⇒ Standalone
constructor
Creates new adaptor listening on a given port.
-
#run ⇒ Object
Start listening for request.
Constructor Details
#initialize(port = 1234) ⇒ Standalone
Creates new adaptor listening on a given port
59 60 61 62 63 64 65 |
# File 'lib/sws/adaptor.rb', line 59 def initialize ( port = 1234 ) @port = port #Always "/" for this class, as the application listens on its own port @base_path = "/" end |
Instance Attribute Details
#port ⇒ Object
Returns the value of attribute port.
56 57 58 |
# File 'lib/sws/adaptor.rb', line 56 def port @port end |
Instance Method Details
#each_request ⇒ Object
Main adaptor method - invokes block for each received request
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/sws/adaptor.rb', line 75 def each_request () while ( socket = @server.accept() ) request = create_request( socket ) response = yield( request ) begin socket.print( "#{response.http_version} #{response.status}\r\n" ) socket.print( response.to_s ) socket.close() rescue => exception $log_sws_request.warn( "Exception #{exception.class} when writing response: #{exception.}" ) end end end |
#run ⇒ Object
Start listening for request
69 70 71 |
# File 'lib/sws/adaptor.rb', line 69 def run () @server = TCPServer.new( @port ) end |