|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectsimpleNetworking.MultiServer
public class MultiServer
A MultiServer first constructs a Server. Then the MultiServer, in its own Thread, repeatedly accepts connections to Clients and sends them to the Server (who can accept or reject them). After constructing a MultiServer, you can ask it to give you the Server that the MultiServer constructs via: -- getServer(N): Returns the Server only after it has N validated Clients -- getServer(): Returns the Server with whatever Clients it currently has, and the MultiServer continues to add Clients to the Server -- getServerAndQuit(): Returns the Server with whatever Clients it currently has, but now the MultiServer stops (so no new Clients are added to the Server by the MultiServer). Or, you can stop the MultiServer at any point and receive the Server that the NOTE: 1. The MultServer must be started before any Clients attempt to connect. 2. Before running this program, you may need to tell your Firewall not to block the port that this program uses (4444, chosen arbitrarily). In Windows, do so by: Control Panel ~ Windows Firewall ~ Exceptions tab ~ Add Port and enter the port number (4444) with any name you like.
Field Summary | |
---|---|
(package private) static int |
PORT
Port to use for establishing connections to this server. |
Constructor Summary | |
---|---|
MultiServer()
Constructs a ServerSocket that this MultiServer uses to accept multiple connections to Clients. |
Method Summary | |
---|---|
(package private) void |
finishUpFailedConstruction(Throwable exception,
String errorMessage)
Something went wrong in constructing this MultiServer. |
Server |
getServer(int requiredNumberOfClients)
Blocks (waits) until the Server created by this MultiServer has validated connections to at least the given number of Clients; then it returns that Server. |
void |
run()
Repeatedly: 1. |
void |
stop()
Stop this MultiThread (which is running in its own Thread) and close all its resources. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
static final int PORT
Constructor Detail |
---|
public MultiServer() throws SocketException
Constructs a ServerSocket that this MultiServer uses to accept multiple connections to Clients. If that ServerSocket is constructed successfully: 1. Construct a Server that runs in its own Thread. 2. In a new Thread, repeatedly: a. Accept a connection, getting a Socket for communicating with a Client. b. Ask the Server to add that Client. -- The Server can run a validation protocol on the proposed Client, accepting or rejecting the proposed Client as it chooses.
SocketException
- if the MultiServer cannot construct a ServerSocket
that uses the default port to accept connections from Clients.Method Detail |
---|
public void run()
run
in interface Runnable
public Server getServer(int requiredNumberOfClients)
requiredNumberOfClients
- Number of Clients required before this method returns.
public void stop()
void finishUpFailedConstruction(Throwable exception, String errorMessage) throws SocketException
exception
- that was thrown by the failed construction of this Client.errorMessage
- to display in a message dialog.
SocketException
- so that the caller knows that construction failed.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |