Class: RxIO::Client
- Inherits:
-
Object
- Object
- RxIO::Client
- Includes:
- Runify, IOBase
- Defined in:
- lib/rxio/client.rb
Overview
Client Class
Constant Summary collapse
- RECONNECT_DELAY =
Reconnect Delay (seconds)
1- SELECT_TIMEOUT =
Select Timeout (seconds)
0.1
Constants included from IOBase
Instance Method Summary collapse
-
#initialize(addr, port, service_handler) ⇒ Client
constructor
Construct Builds a Client around a given service_handler module, set to connect to addr on port.
-
#run ⇒ Object
Run Executes the main client loop, taking care of I/O scheduling and message handling.
-
#send_msg(msg) ⇒ Object
Send Message Enqueues a Message to be sent to the server.
-
#stop ⇒ Object
Stop Requests the client loop to stop executing.
Methods included from IOBase
#drop_endpoint, #process_input, #read_sock, #write_sock
Constructor Details
#initialize(addr, port, service_handler) ⇒ Client
Construct Builds a Client around a given service_handler module, set to connect to addr on port.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rxio/client.rb', line 35 def initialize addr, port, service_handler # Set Address & Port @addr = addr @port = port # Set Service Handler Module @service_handler = service_handler # Set Socket @sock = nil # Client Hash @client = { client: self, ibuf: '', obuf: '', lock: Mutex.new, msgs: [] } end |
Instance Method Details
#run ⇒ Object
Run Executes the main client loop, taking care of I/O scheduling and message handling.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/rxio/client.rb', line 71 def run # Update Loop begin # Update Service update until @stop rescue Exception => e puts "[!] ERROR - RxIO Client Update failed - #{e.inspect}" e.backtrace.each { |b| puts " - #{b}" } end # Drop Socket @sock.close if @sock @sock = nil end |
#send_msg(msg) ⇒ Object
Send Message Enqueues a Message to be sent to the server
60 61 62 63 64 65 66 67 |
# File 'lib/rxio/client.rb', line 60 def send_msg msg # Verify Implementation raise "Method send_msg is not implemented by Service Handler #{@service_handler.name}" unless @service_handler.respond_to? :send_msg # Send Message through Service Handler @service_handler.send_msg @client, msg end |
#stop ⇒ Object
Stop Requests the client loop to stop executing. The run method should return shortly after calling stop
91 92 93 |
# File 'lib/rxio/client.rb', line 91 def stop @stop = true end |