Module: Hara::ClientInteraction
Instance Attribute Summary collapse
-
#client_ip ⇒ Object
readonly
Returns the value of attribute client_ip.
-
#client_port ⇒ Object
readonly
Returns the value of attribute client_port.
-
#handshake ⇒ Object
readonly
Returns the value of attribute handshake.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Instance Method Summary collapse
-
#close(code = nil, body = nil) ⇒ Object
close connection.
-
#headers ⇒ Object
get client headers.
- #response_msg(msg) ⇒ Object
-
#send_msg(msg) ⇒ Object
send msg to client.
- #socket_setup(handshake, socket) ⇒ Object
Instance Attribute Details
#client_ip ⇒ Object (readonly)
Returns the value of attribute client_ip.
6 7 8 |
# File 'lib/hara/client_interaction.rb', line 6 def client_ip @client_ip end |
#client_port ⇒ Object (readonly)
Returns the value of attribute client_port.
6 7 8 |
# File 'lib/hara/client_interaction.rb', line 6 def client_port @client_port end |
#handshake ⇒ Object (readonly)
Returns the value of attribute handshake.
6 7 8 |
# File 'lib/hara/client_interaction.rb', line 6 def handshake @handshake end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
6 7 8 |
# File 'lib/hara/client_interaction.rb', line 6 def socket @socket end |
Instance Method Details
#close(code = nil, body = nil) ⇒ Object
close connection
30 31 32 |
# File 'lib/hara/client_interaction.rb', line 30 def close code = nil, body = nil @socket.close code, body end |
#headers ⇒ Object
get client headers
15 16 17 |
# File 'lib/hara/client_interaction.rb', line 15 def headers handshake.headers_downcased end |
#response_msg(msg) ⇒ Object
25 26 27 |
# File 'lib/hara/client_interaction.rb', line 25 def response_msg msg raise NotImplementedError end |
#send_msg(msg) ⇒ Object
send msg to client
20 21 22 23 |
# File 'lib/hara/client_interaction.rb', line 20 def send_msg msg = Hara.encode_msg(type: :push, args: msg) socket.send end |
#socket_setup(handshake, socket) ⇒ Object
8 9 10 11 12 |
# File 'lib/hara/client_interaction.rb', line 8 def socket_setup handshake, socket @handshake = handshake @socket = socket @client_port, @client_ip = Socket.unpack_sockaddr_in(socket.get_peername) #to get ip address of user end |