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"

Instance Method Summary collapse

Constructor Details

#initialize(port, host_name = 'localhost', millisecond_response_timeout = nil) ⇒ 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’

  • millisecond_response_timeout (Integer) (defaults to: nil)

    The dealer’s response timeout, in milliseconds.

Raises:

  • AcpcDealerConnectionError, UnableToWriteToDealer



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

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

    @response_timeout_in_seconds = if millisecond_response_timeout
      millisecond_response_timeout/(10**3).to_r
    else
      nil
    end

    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



87
88
89
90
91
92
93
# File 'lib/acpc_poker_basic_proxy/dealer_stream.rb', line 87

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?


114
115
116
# File 'lib/acpc_poker_basic_proxy/dealer_stream.rb', line 114

def ready_to_read?
  @dealer_socket.ready_to_read? @response_timeout_in_seconds
end

#ready_to_write?Boolean

Returns:

  • (Boolean)

See Also:

  • TCPSocket#ready_to_write?


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

def ready_to_write?
  @dealer_socket.ready_to_write? @response_timeout_in_seconds
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



100
101
102
103
104
105
106
# File 'lib/acpc_poker_basic_proxy/dealer_stream.rb', line 100

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