Class: AcpcPokerBasicProxy::DealerStream

Inherits:
TCPSocket
  • Object
show all
Defined in:
lib/acpc_poker_basic_proxy/dealer_stream.rb

Constant Summary collapse

VERSION_LABEL =
'VERSION'
VERSION_NUMBERS =
{:major => 2, :minor => 0, :revision => 0}
TERMINATION_STRING =
"\r\n"
READY_MESSAGE =
'#READY'

Instance Method Summary collapse

Constructor Details

#initialize(port, host_name = 'localhost') ⇒ DealerStream

Returns a new instance of DealerStream

Raises:

  • AcpcDealerConnectionError, UnableToWriteToDealer


65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/acpc_poker_basic_proxy/dealer_stream.rb', line 65

def initialize(port, host_name='localhost')
  @dealer_socket = nil
  begin
    @dealer_socket = TCPSocket.new(host_name, port)
    super @dealer_socket

    send_version_string_to_dealer
  rescue UnableToWriteToDealer
    raise
  rescue Errno::ECONNREFUSED => e
    handle_error UnableToConnectToDealer, "Unable to connect to the dealer on #{host_name} through port #{port}", e
  end
end

Instance Method Details

#getsString

Retrieves a string from the dealer.

Raises:

  • UnableToGetFromDealer


83
84
85
86
87
88
89
# File 'lib/acpc_poker_basic_proxy/dealer_stream.rb', line 83

def gets
  begin
    string_from_dealer
  rescue => e
    handle_error UnableToGetFromDealer, "Unable to get a string from the dealer", e
  end
end

#ready_to_read?Boolean

See Also:

  • TCPSocket#ready_to_read?

110
111
112
# File 'lib/acpc_poker_basic_proxy/dealer_stream.rb', line 110

def ready_to_read?
  @dealer_socket.ready_to_read?
end

#ready_to_write?Boolean

See Also:

  • TCPSocket#ready_to_write?

105
106
107
# File 'lib/acpc_poker_basic_proxy/dealer_stream.rb', line 105

def ready_to_write?
  @dealer_socket.ready_to_write?
end

#write(string) ⇒ Integer

Sends a given string to the dealer.

Raises:

  • UnableToWriteToDealer


96
97
98
99
100
101
102
# File 'lib/acpc_poker_basic_proxy/dealer_stream.rb', line 96

def write(string)
  begin
    send_string_to_dealer string
  rescue => e
    handle_error UnableToWriteToDealer, "Unable to send the string, \"#{string}\", to the dealer", e
  end
end