All Packages Class Hierarchy This Package Previous Next Index
Class breakout.ClientHandler
java.lang.Object
|
+----breakout.ClientHandler
- public class ClientHandler
- extends java.lang.Object
- implements java.lang.Runnable
A class that connects BOClient and BOServer.
Works with BOServer.java and ClientHandler.java.
It implements Runnable.
- Author:
- Jennifer Shieh
- See Also:
- java.lang.Runnable, breakout.BOServer, breakout.BOClient
-
client
- the Socket connected to the BOClient
-
currentPlayerCount
- An int to keep track of current number of players
-
dis
- A DataInputStream
-
dos
- A DataOutputStream
-
runner
- A Thread
-
server
- A BOServer
-
ClientHandler(Socket, BOServer)
- The constructor takes a Socket and a BOServer as parameters.
-
read()
- Reads one int from the Client.
-
run()
- Runnable's run() method.
-
send(int)
- Sends the specified int to the BOClient connected by the DataOutputStream.
-
sendCoords(int, int)
- Sends two ints, x and y coordinates, to the BOClient connected by the DataOutputStream.
server
private breakout.BOServer server
- A BOServer
client
private java.net.Socket client
- the Socket connected to the BOClient
dis
private java.io.DataInputStream dis
- A DataInputStream
dos
private java.io.DataOutputStream dos
- A DataOutputStream
runner
private java.lang.Thread runner
- A Thread
currentPlayerCount
private int currentPlayerCount
- An int to keep track of current number of players
ClientHandler
public ClientHandler(java.net.Socket s,
breakout.BOServer server)
- The constructor takes a Socket and a BOServer as parameters. It creates new DataInputStreams and DataOutputStreams
connected to the Socket passed in as an argument. Equates its field currentPlayerCount to the BOServer's currentPlayerCount.
Also, creates a new Thread on this Object and starts the Thread running.
- Parameters:
- Socket - the Socket through which this ClientHandler is connected to a client
- BOServer - the central server through which information is broadcast
run
public void run()
- Runnable's run() method. Continuously reads any x and y coordinates being sent by its BOClient, and writes those
coordinates to everyone except its BOClient.
Catches IOException.
- See Also:
- writeOneInt, writeToAllExcept, readInt
send
public void send(int i)
- Sends the specified int to the BOClient connected by the DataOutputStream. Flushes after every write.
- Parameters:
- int - i the int which should be sent
- See Also:
- writeInt, flush
sendCoords
public void sendCoords(int x,
int y)
- Sends two ints, x and y coordinates, to the BOClient connected by the DataOutputStream. Flushes after every write.
- Parameters:
- int - x the x coordinate to be sent
- int - y the y coordinate to be sent
- See Also:
- writeInt, flush
read
public int read()
- Reads one int from the Client. Returns that int. Generally, either the x or the y coordinate of the ball.
- Returns:
- i the int read from the DataInputStream
- See Also:
- readInt
All Packages Class Hierarchy This Package Previous Next Index