All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class breakout.BOServer

java.lang.Object
   |
   +----breakout.BOServer

public class BOServer
extends java.lang.Object
implements java.lang.Runnable
A class which creates a Socket to listen on and can communicate with multiple clients. Works with BOClient.java and ClientHandler.java. Uses Gamefinder, created by Mike Wessler, so the game can be connected to by people. It implements Runnable.

Author:
Jennifer Shieh
See Also:
java.lang.Runnable, breakout.BOClient, breakout.ClientHandler

Variable Index

 o clientHandlers
A Vector of ClientHandlers
 o currentPlayerCount
This is a field to keep track of the current number of players playing Breakout!
 o gf
A GameFinder
 o runner
A Thread
 o ss
A ServerSocket

Constructor Index

 o BOServer()
Constructor takes no arguments; creates a new ServerSocket on port 4321 Creates and starts a new Thread on this Object.

Method Index

 o removeClientHandler(ClientHandler)
Method to remove the ClientHandler specified as a parameter from the vector of ClientHandlers.
 o run()
Runnable's run() method.
 o writeOne(int, ClientHandler)
Method to send one int to all the clients except client that generated the int.
 o writeOneInt(int, ClientHandler)
Method to send one int to all the clients, used to send player ID to Clients.
 o writeToAllExcept(int, int, ClientHandler)
Method to send the center coordinates of balls, represented by ints.

Variables

 o clientHandlers
 private java.util.Vector clientHandlers
A Vector of ClientHandlers

 o ss
 private java.net.ServerSocket ss
A ServerSocket

 o runner
 private java.lang.Thread runner
A Thread

 o currentPlayerCount
 public int currentPlayerCount
This is a field to keep track of the current number of players playing Breakout!

 o gf
 private gamefinder.GameFinder gf
A GameFinder

Constructors

 o BOServer
 public BOServer()
Constructor takes no arguments; creates a new ServerSocket on port 4321 Creates and starts a new Thread on this Object. Catches IOException.

Methods

 o run
 public void run()
Runnable's run() method. Accepts a connection, creating a Socket to listen on. If a Socket has been created, a new ClientHandler will be created and connected to that Socket and this BOServer. That ClientHandler is then added to a vector of ClientHandlers. Also increases the currentPlayerCount field by 1 to keep track of number of opened Sockets/ Clients. Catches IOException.

See Also:
currentPlayerCount, writeOneInt, accept
 o writeToAllExcept
 public synchronized void writeToAllExcept(int x,
                                           int y,
                                           breakout.ClientHandler ch)
Method to send the center coordinates of balls, represented by ints. Sends information to all ClientHandlers except the ClientHandler passed in as an argument, meant to be the ClientHandler that sent the information. Uses ClientHandler's sendCoords(int x, int y) method.

Parameters:
x - the x coordinate of the ball
y - the y coordinate of the ball
ClientHandler - the ClientHandler that sent the x and y coordinates
See Also:
sendCoords
 o writeOneInt
 public synchronized void writeOneInt(int i,
                                      breakout.ClientHandler ch)
Method to send one int to all the clients, used to send player ID to Clients. Sends information to all ClientHandlers. Sent by the ClientHandler that Uses ClientHandler's send(int i) method.

Parameters:
i - any integer that should be sent to all ClientHandlers
ClientHandler - the ClientHandler that should send the data, generally the one that produced the number
See Also:
send
 o writeOne
 public synchronized void writeOne(int i,
                                   breakout.ClientHandler ch)
Method to send one int to all the clients except client that generated the int. Not sent to ClientHandler passed in as a parameter, which is meant to be the ClientHandler whose client is sending the int. Uses ClientHandler's send(int i) method.

Parameters:
i - any integer that should be sent to other players
ClientHandler - the ClientHandler that sent the data and should be excluded from being sent this information again
See Also:
send
 o removeClientHandler
 public void removeClientHandler(breakout.ClientHandler ch)
Method to remove the ClientHandler specified as a parameter from the vector of ClientHandlers.


All Packages  Class Hierarchy  This Package  Previous  Next  Index