glassfrog.players
Class SocketPlayer

java.lang.Object
  extended by glassfrog.players.Player
      extended by glassfrog.players.SocketPlayer
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<Player>
Direct Known Subclasses:
GUIPlayer

public class SocketPlayer
extends Player

The SocketPlayer class allows for players to connect to the game via socket. A Socket must be passed in to the constructor, which then sets up the PrintWriter and BufferedReader from which the actions are sent and recieved from agents

Author:
jdavidso
See Also:
Serialized Form

Field Summary
protected  java.io.BufferedReader br
          The buffered reader for the socket.
protected  java.io.PrintWriter pw
          The print writer for the socket
protected  java.net.Socket socket
          The socket returned after a successfull connection
protected  java.net.ServerSocket ss
          The server socket on which the player is to connect
private  int TIMEOUT
           
 
Constructor Summary
SocketPlayer()
          Empty default contructor for extendability
SocketPlayer(java.lang.String name, int buyIn, java.io.BufferedReader br, java.io.PrintWriter pw)
          A contructror for SocketPlayer that takes a @BufferedReader and a @PrintWriter and established the player based on the pre-establised in and out.
SocketPlayer(java.lang.String name, int buyIn, int port)
          A contructor for Socket Player that takes a name, buyIn, a seat request and a port for connection
SocketPlayer(java.lang.String name, int buyIn, java.net.Socket socket)
          The SocketPlayer constructor that takes a port and opens a socket connection to handle action requests and updates to the player over a socket
 
Method Summary
 java.lang.String getAction()
          Gets the action of the player through the BufferedReader
 int getPort()
          Returns the port the agent is connected to the player on
 java.net.Socket getSocket()
          Return the @Socket the player is using
private  void initPlayer()
          Set up the Players reader and writer.
 void initTimeout()
          Used to set the player timeout to 60s per hand
 boolean isSocketPlayer()
          Overrides the @Player implementation of isSocketPlayer and returns True
 void reconnect(java.net.Socket s)
          The reconnect method allows for a player to be reconnected on @Dealer load
 void shutdown()
          Closes down all sockets and I/O on shutdown
 void update(java.lang.String gamestate)
          Send the gamestate to the player through the PrintWriter
 
Methods inherited from class glassfrog.players.Player
addToScore, bet, call, compareTo, fold, getBuyIn, getCardString, getCurrentBet, getHandRank, getHandString, getName, getPosition, getScore, getSeat, getStack, getTotalCommitedToPot, initTimeout, isAAAIPlayer, isActed, isAllIn, isFolded, isGuiPlayer, payout, postBlind, resetHand, resetPlayer, resetRound, resetStack, setBuyIn, setCardString, setHandRank, setHandString, setName, setPosition, setScore, setSeat, setStack, subtractTotalCommitedToPot, toShortString, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ss

protected transient java.net.ServerSocket ss
The server socket on which the player is to connect


socket

protected transient java.net.Socket socket
The socket returned after a successfull connection


br

protected transient java.io.BufferedReader br
The buffered reader for the socket.


pw

protected transient java.io.PrintWriter pw
The print writer for the socket


TIMEOUT

private final transient int TIMEOUT
See Also:
Constant Field Values
Constructor Detail

SocketPlayer

public SocketPlayer()
Empty default contructor for extendability


SocketPlayer

public SocketPlayer(java.lang.String name,
                    int buyIn,
                    int port)
A contructor for Socket Player that takes a name, buyIn, a seat request and a port for connection

Parameters:
name - a @String representing the name of the player
buyIn - an int representing the requested buyIn amount
port - an int representing a port to establish a connection on

SocketPlayer

public SocketPlayer(java.lang.String name,
                    int buyIn,
                    java.net.Socket socket)
             throws java.io.IOException
The SocketPlayer constructor that takes a port and opens a socket connection to handle action requests and updates to the player over a socket

Parameters:
name - A string representing the player's name
buyIn - an int representing the player's buyIn
socket - a socket to which the player is connected to an agent
Throws:
java.io.IOException

SocketPlayer

public SocketPlayer(java.lang.String name,
                    int buyIn,
                    java.io.BufferedReader br,
                    java.io.PrintWriter pw)
             throws java.io.IOException
A contructror for SocketPlayer that takes a @BufferedReader and a @PrintWriter and established the player based on the pre-establised in and out.

Parameters:
name - a @String representing the name of the player
buyIn - an int representing the requested buyIn amount
br - A @BufferedReader the player will recieve gamestate information on
pw - A @APrintWriter the player will print action to
Throws:
java.io.IOException
Method Detail

getPort

public int getPort()
Returns the port the agent is connected to the player on

Returns:
an int representing the port number the agent is connected on

getAction

public java.lang.String getAction()
Gets the action of the player through the BufferedReader

Specified by:
getAction in class Player
Returns:
the action sent or throw a NullPointerException on disconnect

update

public void update(java.lang.String gamestate)
Send the gamestate to the player through the PrintWriter

Specified by:
update in class Player
Parameters:
gamestate - The gamestate to send

initPlayer

private void initPlayer()
                 throws java.io.IOException
Set up the Players reader and writer.

Throws:
java.io.IOException

isSocketPlayer

public boolean isSocketPlayer()
Overrides the @Player implementation of isSocketPlayer and returns True

Overrides:
isSocketPlayer in class Player
Returns:
True

reconnect

public void reconnect(java.net.Socket s)
               throws java.io.IOException
The reconnect method allows for a player to be reconnected on @Dealer load

Parameters:
s - The @Socket for the player to be reconnected on
Throws:
java.io.IOException

getSocket

public java.net.Socket getSocket()
Return the @Socket the player is using

Returns:
the @Socket the player is currently using

shutdown

public void shutdown()
Closes down all sockets and I/O on shutdown

Specified by:
shutdown in class Player

initTimeout

public void initTimeout()
Used to set the player timeout to 60s per hand