Class: Whatup::Client::Client

Inherits:
Object
  • Object
show all
Includes:
Thor::Shell
Defined in:
lib/whatup/client/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(ip:, port:) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
16
# File 'lib/whatup/client/client.rb', line 10

def initialize ip:, port:
  @dest = {
    ip: ip,
    port: port,
    address: "#{@ip}:#{@port}"
  }
end

Instance Method Details

#connectObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/whatup/client/client.rb', line 18

def connect
  say "Connecting to #{@dest[:ip]}:#{@dest[:port]} ..."

  @socket = TCPSocket.open @dest[:ip], @dest[:port]

  puts 'Please enter your username to establish a connection...'
  @request = request!
  @response = listen!

  [@request, @response].each &:join
rescue SignalException
  say 'Exiting ...', :red
  exit
end