java.lang.Object
|
+--java.lang.Thread
|
+--de.cgarbs.net.LoginServer
A multi-client TCP server with username/password access control. This server binds to a port and waits for connections. It then spawns LoginServerThreads. In order to create your own server you have to extend the LoginServerThread class to your needs.
This class is licensed under the GNU GENERAL PUBLIC LICENSE.
LoginServerThread| Field Summary | |
static int |
ALLOW
This doubleLoginPolicy allows a user to be connected to this LoginServer several times at once. |
static int |
DENY
This doubleLoginPolicy denies any additional connections to a particular user when he is already logged on at this LoginServer. |
static int |
KICK
This doubleLoginPolicy will close the first (=old) connection when a user logs on twice at this LoginServer. |
| Fields inherited from class java.lang.Thread |
MAX_PRIORITY,
MIN_PRIORITY,
NORM_PRIORITY |
| Constructor Summary | |
LoginServer(java.lang.Class threadClass,
java.io.OutputStream log,
java.util.Hashtable passwd,
int port,
java.lang.String serverName)
constructor with no connection limit, allowing multiple logons with the same username (backwards compatible with version 0.0.1) |
|
LoginServer(java.lang.Class threadClass,
java.io.OutputStream log,
java.util.Hashtable passwd,
int port,
java.lang.String serverName,
int doubleLoginPolicy)
constructor with no connection limit |
|
LoginServer(java.lang.Class threadClass,
java.io.OutputStream log,
java.util.Hashtable passwd,
int port,
java.lang.String serverName,
int doubleLoginPolicy,
int maxConnections)
standard constructor |
|
| Method Summary | |
void |
accept()
Tells the server to accept client connections. |
int |
connections()
Returns the number of active connections (=number of LoginServerThreads). |
java.lang.String |
getServerName()
Returns the name of this server. |
boolean |
isOpen()
Tells whether client connections will be accepted. |
boolean |
isStarted()
Tells whether the server started and listening on the given port. |
void |
kick()
Closes all active client connections (kills all LoginServerThreads). |
boolean |
registerThread(LoginServerThread thread)
The LoginServerThreads must register here after their creation. |
void |
reject()
Tells the server to reject client connections. |
void |
run()
Listens on the server socket. |
void |
setPort(int port)
Changes the server port. |
void |
setSoTimeout(int socketTimeout)
Changes the socket timeout. |
void |
shutdown()
Stops the server and closes the server socket. |
void |
startup()
Opens the server socket to allow clients to connect. |
boolean |
unregisterThread(LoginServerThread thread)
The LoginServerThreads must unregister here before they exit. |
| Methods inherited from class java.lang.Thread |
activeCount,
checkAccess,
countStackFrames,
currentThread,
destroy,
dumpStack,
enumerate,
getContextClassLoader,
getName,
getPriority,
getThreadGroup,
interrupt,
interrupted,
isAlive,
isDaemon,
isInterrupted,
join,
join,
join,
resume,
setContextClassLoader,
setDaemon,
setName,
setPriority,
sleep,
sleep,
start,
stop,
stop,
suspend,
toString,
yield |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
| Field Detail |
public static final int ALLOW
public static final int KICK
public static final int DENY
| Constructor Detail |
public LoginServer(java.lang.Class threadClass,
java.io.OutputStream log,
java.util.Hashtable passwd,
int port,
java.lang.String serverName,
int doubleLoginPolicy,
int maxConnections)
threadClass - The class of LoginServerThreads that are spawned to
serve the clients.log - Log messages go here.passwd - Valid username/password pairs (key = username, value =
password).port - The TCP port the server listens on.serverName - The name of this server.doubleLoginPolicy - What to do when a user logs on twice (can be
ALLOW, KICK or DENY).maxConnections - The maximum number of simultaneous connections
allowed to this server.
public LoginServer(java.lang.Class threadClass,
java.io.OutputStream log,
java.util.Hashtable passwd,
int port,
java.lang.String serverName,
int doubleLoginPolicy)
threadClass - The class of LoginServerThreads that are spawned to
serve the clients.log - Log messages go here.passwd - Valid username/password pairs (key = username, value =
password).port - The TCP port the server listens on.serverName - The name of this server.doubleLoginPolicy - The maximum number of simultaneous connections
allowed to this server.
public LoginServer(java.lang.Class threadClass,
java.io.OutputStream log,
java.util.Hashtable passwd,
int port,
java.lang.String serverName)
threadClass - The class of LoginServerThreads that are spawned to
serve the clients.log - Log messages go here.passwd - Valid username/password pairs (key = username, value =
password).port - The TCP port the server listens on.serverName - The name of this server.| Method Detail |
public void setSoTimeout(int socketTimeout)
socketTimeout - Timeout in milliseconds (default=1000msec).public void setPort(int port)
port - new port to listen topublic void accept()
public void reject()
public void kick()
public boolean isStarted()
public boolean isOpen()
public void shutdown()
public void startup()
public boolean registerThread(LoginServerThread thread)
thread - the LoginServerThread that did the requestpublic int connections()
public boolean unregisterThread(LoginServerThread thread)
thread - the LoginServerThread that did the requestpublic void run()
public java.lang.String getServerName()