Class: AcpcPokerBasicProxy::DealerStream

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

Constant Summary collapse

VERSION_LABEL =

Returns The ACPC dealer version label.

Returns:

  • (String)

    The ACPC dealer version label.

'VERSION'
VERSION_NUMBERS =

Returns The ACPC dealer version numbers.

Returns:

  • (Hash)

    The ACPC dealer version numbers.

{:major => 2, :minor => 0, :revision => 0}
TERMINATION_STRING =

Returns Dealer specified string terminator.

Returns:

  • (String)

    Dealer specified string terminator.

"\r\n"
READY_MESSAGE =
'#READY'

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of DealerStream.

Parameters:

  • port (Integer)

    The port on which to connect to the dealer.

  • host_name (String) (defaults to: 'localhost')

    The host on which the dealer is running. Defaults to ‘localhost’

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.

Returns:

  • (String)

    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

Returns:

  • (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

Returns:

  • (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.

Parameters:

  • string (String)

    The string to send.

Returns:

  • (Integer)

    The number of bytes written 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