Class: FiverrCopy::Client
- Inherits:
-
Object
- Object
- FiverrCopy::Client
- Defined in:
- lib/fiverr_copy/client.rb
Instance Attribute Summary collapse
-
#client_ip ⇒ Object
readonly
Returns the value of attribute client_ip.
-
#next_client ⇒ Object
readonly
Returns the value of attribute next_client.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
- #forward? ⇒ Boolean
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #ready? ⇒ Boolean
- #setup! ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 10 11 12 13 |
# File 'lib/fiverr_copy/client.rb', line 5 def initialize( = {}) #options.assert_valid_keys :client_ip, :next_client, :username, :port @next_client = [:next_client] ||= nil @username = [:username] ||= "admin" @client_ip = [:client_ip]# || raise("No client specified") @port = [:port] ||= 1234 @ready = false self end |
Instance Attribute Details
#client_ip ⇒ Object (readonly)
Returns the value of attribute client_ip.
3 4 5 |
# File 'lib/fiverr_copy/client.rb', line 3 def client_ip @client_ip end |
#next_client ⇒ Object (readonly)
Returns the value of attribute next_client.
3 4 5 |
# File 'lib/fiverr_copy/client.rb', line 3 def next_client @next_client end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
3 4 5 |
# File 'lib/fiverr_copy/client.rb', line 3 def port @port end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
3 4 5 |
# File 'lib/fiverr_copy/client.rb', line 3 def username @username end |
Class Method Details
.run!(port, next_client, filename, chunk) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fiverr_copy/client.rb', line 28 def self.run!(port, next_client, filename, chunk) puts "FiverrCopy client initializing" server = TCPServer.new(port) session = server.accept client_session = nil if !(next_client.nil?) client_session = TCPSocket.new(next_client, port) end File.open(filename, "w+") do |f| # Thread.start do while (stream = session.read(chunk.to_i)) do f.write stream if !(next_client.nil?) client_session.write(stream) end session.puts "OK:#{stream.size}" end end end |
Instance Method Details
#forward? ⇒ Boolean
15 16 17 |
# File 'lib/fiverr_copy/client.rb', line 15 def forward? !(@next_client.nil?) end |
#ready? ⇒ Boolean
19 20 21 |
# File 'lib/fiverr_copy/client.rb', line 19 def ready? @ready end |
#setup! ⇒ Object
23 24 25 |
# File 'lib/fiverr_copy/client.rb', line 23 def setup! @ready = true end |