Class: Gt06Server::Session
- Inherits:
-
Object
- Object
- Gt06Server::Session
- Defined in:
- lib/gt06_server/session.rb
Defined Under Namespace
Classes: SessionError
Instance Attribute Summary collapse
-
#addr ⇒ Object
readonly
Returns the value of attribute addr.
-
#info ⇒ Object
readonly
Returns the value of attribute info.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
-
#terminal_id ⇒ Object
readonly
Returns the value of attribute terminal_id.
Instance Method Summary collapse
-
#initialize(socket, logger: Logger.new(STDOUT)) ⇒ Session
constructor
A new instance of Session.
- #inspect ⇒ Object
- #run {|Hash| ... } ⇒ Object
Constructor Details
#initialize(socket, logger: Logger.new(STDOUT)) ⇒ Session
Returns a new instance of Session.
9 10 11 12 13 14 15 16 17 |
# File 'lib/gt06_server/session.rb', line 9 def initialize(socket, logger: Logger.new(STDOUT)) @socket = socket @addr = socket.peeraddr @terminal_id = '' @info = { received_count: 0, sent_count: 0, last_received_at: Time.now} @logger = logger logger.debug 'New session has been created' end |
Instance Attribute Details
#addr ⇒ Object (readonly)
Returns the value of attribute addr.
6 7 8 |
# File 'lib/gt06_server/session.rb', line 6 def addr @addr end |
#info ⇒ Object (readonly)
Returns the value of attribute info.
6 7 8 |
# File 'lib/gt06_server/session.rb', line 6 def info @info end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
6 7 8 |
# File 'lib/gt06_server/session.rb', line 6 def logger @logger end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
6 7 8 |
# File 'lib/gt06_server/session.rb', line 6 def socket @socket end |
#terminal_id ⇒ Object (readonly)
Returns the value of attribute terminal_id.
6 7 8 |
# File 'lib/gt06_server/session.rb', line 6 def terminal_id @terminal_id end |
Instance Method Details
#inspect ⇒ Object
29 30 31 |
# File 'lib/gt06_server/session.rb', line 29 def inspect "#{object_id} Terminal id:#{@terminal_id}, ip: #{@addr}, #{@info}" end |
#run {|Hash| ... } ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/gt06_server/session.rb', line 21 def run(&block) handle_head_pack(Protocol.read_pack(@socket)) loop do handle_main_pack(Protocol.read_pack(@socket), &block) end end |