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

Variable Index

 o client
the Socket connected to the BOClient
 o currentPlayerCount
An int to keep track of current number of players
 o dis
A DataInputStream
 o dos
A DataOutputStream
 o runner
A Thread
 o server
A BOServer

Constructor Index

 o ClientHandler(Socket, BOServer)
The constructor takes a Socket and a BOServer as parameters.

Method Index

 o read()
Reads one int from the Client.
 o run()
Runnable's run() method.
 o send(int)
Sends the specified int to the BOClient connected by the DataOutputStream.
 o sendCoords(int, int)
Sends two ints, x and y coordinates, to the BOClient connected by the DataOutputStream.

Variables

 o server
 private breakout.BOServer server
A BOServer

 o client
 private java.net.Socket client
the Socket connected to the BOClient

 o dis
 private java.io.DataInputStream dis
A DataInputStream

 o dos
 private java.io.DataOutputStream dos
A DataOutputStream

 o runner
 private java.lang.Thread runner
A Thread

 o currentPlayerCount
 private int currentPlayerCount
An int to keep track of current number of players

Constructors

 o 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

Methods

 o 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
 o 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
 o 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
 o 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