Class: Process::Roulette::Controller::ConnectHandler
- Inherits:
-
Object
- Object
- Process::Roulette::Controller::ConnectHandler
- Defined in:
- lib/process/roulette/controller/connect_handler.rb
Overview
Handles the CONNECT state of the controller state machine. Connects to the croupier, performs the handshake, and advances to COMMAND state.
Instance Method Summary collapse
- #_handshake(socket) ⇒ Object
-
#initialize(driver) ⇒ ConnectHandler
constructor
A new instance of ConnectHandler.
- #run ⇒ Object
Constructor Details
#initialize(driver) ⇒ ConnectHandler
Returns a new instance of ConnectHandler.
12 13 14 |
# File 'lib/process/roulette/controller/connect_handler.rb', line 12 def initialize(driver) @driver = driver end |
Instance Method Details
#_handshake(socket) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/process/roulette/controller/connect_handler.rb', line 28 def _handshake(socket) socket.send_packet(@driver.password || 'OK') packet = socket.wait_with_ping abort 'lost connection' unless packet abort "unexpected packet #{packet.inspect}" unless packet == 'OK' end |
#run ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/process/roulette/controller/connect_handler.rb', line 16 def run puts 'connecting...' socket = TCPSocket.new(@driver.host, @driver.port) Roulette::EnhanceSocket(socket) _handshake(socket) @driver.socket = socket Controller::CommandHandler end |