Module: Hara::ClientInteraction

Included in:
App, Filter
Defined in:
lib/hara/client_interaction.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#client_ipObject (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_portObject (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

#handshakeObject (readonly)

Returns the value of attribute handshake.



6
7
8
# File 'lib/hara/client_interaction.rb', line 6

def handshake
  @handshake
end

#socketObject (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

#headersObject

get client headers



15
16
17
# File 'lib/hara/client_interaction.rb', line 15

def headers
  handshake.headers_downcased
end

#response_msg(msg) ⇒ Object

Raises:

  • (NotImplementedError)


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
  message = Hara.encode_msg(type: :push, args: msg)
  socket.send message
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