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
-
clientHandlers
- A Vector of ClientHandlers
-
currentPlayerCount
- This is a field to keep track of the current number of players playing Breakout!
-
gf
- A GameFinder
-
runner
- A Thread
-
ss
- A ServerSocket
-
BOServer()
- Constructor takes no arguments; creates a new ServerSocket on port 4321
Creates and starts a new Thread on this Object.
-
removeClientHandler(ClientHandler)
- Method to remove the ClientHandler specified as a parameter from the vector of ClientHandlers.
-
run()
- Runnable's run() method.
-
writeOne(int, ClientHandler)
- Method to send one int to all the clients except client that generated the int.
-
writeOneInt(int, ClientHandler)
- Method to send one int to all the clients, used to send player ID to Clients.
-
writeToAllExcept(int, int, ClientHandler)
- Method to send the center coordinates of balls, represented by ints.
clientHandlers
private java.util.Vector clientHandlers
- A Vector of ClientHandlers
ss
private java.net.ServerSocket ss
- A ServerSocket
runner
private java.lang.Thread runner
- A Thread
currentPlayerCount
public int currentPlayerCount
- This is a field to keep track of the current number of players playing Breakout!
gf
private gamefinder.GameFinder gf
- A GameFinder
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.
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
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
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
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
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