Package ucar.unidata.collab
Class Server
java.lang.Object
ucar.unidata.collab.Server
- Direct Known Subclasses:
CollabServer
A generic server
- Author:
- Metapps development team
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd the given client to the list of clients managed by this server.voidAdd the given client to the list of clients managed by this server.protected ClientcreateClient(Socket clientSocket) A factory method for creating a new client.Gets the clients.booleanGet the IsRunning property.protected voidhandleIncomingMessage(Client fromClient, String message) Handle the message rcvd from the given client.booleanDoes this server have any clients.protected voidinitClient(Socket clientSocket) Create a new client object and listen for input.protected voidlogException(String msg, Exception exc) Log exception.static voidThe main method.protected voidnotifyClientAdd(Client client) Gets called when we have added a new client.protected voidnotifyClientRemove(Client client) Gets called when we have removed a client.protected voidGets called when we are starting to listenprotected voidGets called when we are done running on the server socketvoidremoveClient(Client client) Remove the given client from the list of clients managed by this server.voidStart server.voidstartServer(int newPort) Start server.voidStop server.voidWrite.voidWrite.
-
Field Details
-
DEFAULT_PORT
public static int DEFAULT_PORT_more_
-
-
Constructor Details
-
Server
public Server()Create a new Server connection. -
Server
public Server(int port) Create a new Server connection on the given port.- Parameters:
port- the port
-
-
Method Details
-
startServer
Start server.- Parameters:
newPort- the new port- Throws:
IOException- Signals that an I/O exception has occurred.
-
startServer
Start server.- Throws:
IOException- Signals that an I/O exception has occurred.
-
stopServer
public void stopServer()Stop server. -
notifyServerStart
protected void notifyServerStart()Gets called when we are starting to listen -
notifyServerStop
protected void notifyServerStop()Gets called when we are done running on the server socket -
notifyClientAdd
Gets called when we have added a new client.- Parameters:
client- the client
-
notifyClientRemove
Gets called when we have removed a client.- Parameters:
client- the client
-
getIsRunning
public boolean getIsRunning()Get the IsRunning property.- Returns:
- The IsRunning
-
createClient
A factory method for creating a new client.- Parameters:
clientSocket- The socket we are connected to the client with.- Returns:
- a new Client
- Throws:
IOException- Signals that an I/O exception has occurred.
-
initClient
Create a new client object and listen for input.- Parameters:
clientSocket- the client socket
-
getClients
Gets the clients.- Returns:
- the clients
-
hasClients
public boolean hasClients()Does this server have any clients.- Returns:
- true, if successful
-
addClient
Add the given client to the list of clients managed by this server.- Parameters:
client- the client
-
addClient
Add the given client to the list of clients managed by this server.- Parameters:
client- the clientandStartListening- the and start listening
-
removeClient
Remove the given client from the list of clients managed by this server.- Parameters:
client- the client
-
handleIncomingMessage
Handle the message rcvd from the given client. The default is to just turn around and write it to each of the other clients.- Parameters:
fromClient- the from clientmessage- the message
-
write
Write.- Parameters:
message- the message
-
write
Write.- Parameters:
message- the messageexceptClient- the except client
-
logException
Log exception.- Parameters:
msg- the msgexc- the exc
-
main
The main method.- Parameters:
args- the arguments
-