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 TypeMethodDescriptionvoid
Add the given client to the list of clients managed by this server.void
Add the given client to the list of clients managed by this server.protected Client
createClient
(Socket clientSocket) A factory method for creating a new client.Gets the clients.boolean
Get the IsRunning property.protected void
handleIncomingMessage
(Client fromClient, String message) Handle the message rcvd from the given client.boolean
Does this server have any clients.protected void
initClient
(Socket clientSocket) Create a new client object and listen for input.protected void
logException
(String msg, Exception exc) Log exception.static void
The main method.protected void
notifyClientAdd
(Client client) Gets called when we have added a new client.protected void
notifyClientRemove
(Client client) Gets called when we have removed a client.protected void
Gets called when we are starting to listenprotected void
Gets called when we are done running on the server socketvoid
removeClient
(Client client) Remove the given client from the list of clients managed by this server.void
Start server.void
startServer
(int newPort) Start server.void
Stop server.void
Write.void
Write.
-
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
-