tw.net
Class Server

java.lang.Object
  extended by tw.net.Server
Direct Known Subclasses:
OCSServer

public abstract class Server
extends java.lang.Object

Abstract multithreaded server

Author:
Tillmann Wegst

Field Summary
static int DEFAULT_PORT
          default port (23229)
static int LOCAL
          pseudo port value for servers directly linked to clients
static int UNBOUND
          value indicating the server socket hasn't been bound to a port yet
 
Method Summary
 void allowClientIP(java.lang.String pattern)
           Adds an IP address or address pattern for clients acceptable by this server.
 void allowClientIPs(java.lang.String[] pattern)
          Adds one or more IP address patterns for clients acceptable by this server.
 void forbidClientIP(java.lang.String pattern)
           Adds an IP address or address pattern for clients not acceptable by this server.
 void forbidClientIPs(java.lang.String[] pattern)
          Adds one or more IP address patterns for clients not acceptable by this server.
 java.lang.String getHostAddress()
          Returns the IP of the host
 java.lang.String getHostName()
          Returns the name of the host
 int getPort()
          Returns the port which this server listens at
 int getPriority()
          Informs about the main server thread's priority
 boolean isDaemon()
          Tells whether the main server thread has daemon quality
static void main(java.lang.String[] args)
           
 void pleaseStop()
          Asks the server to stop working
 void setDaemon(boolean a)
          Sets the main server thread's daemon quality
 void setPriority(int a)
          Sets the main server thread's priority
 void setVerbose(boolean value)
           Tells the server to print some accompanying messages to the console.
 void start()
           Starts the Server.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PORT

public static final int DEFAULT_PORT
default port (23229)

See Also:
Constant Field Values

LOCAL

public static final int LOCAL
pseudo port value for servers directly linked to clients

See Also:
Constant Field Values

UNBOUND

public static final int UNBOUND
value indicating the server socket hasn't been bound to a port yet

See Also:
Constant Field Values
Method Detail

start

public void start()
Starts the Server.

Provided it is not the special case of a
server directly linked to a client, it will
begin to listen for clients.
                


setDaemon

public void setDaemon(boolean a)
Sets the main server thread's daemon quality

Parameters:
a - make the thread a daemon?

isDaemon

public boolean isDaemon()
Tells whether the main server thread has daemon quality

Returns:
true if and only if the thread is in daemon mode

setPriority

public void setPriority(int a)
Sets the main server thread's priority

Parameters:
a - the desired priority

getPriority

public int getPriority()
Informs about the main server thread's priority

Returns:
the priority

getHostName

public java.lang.String getHostName()
Returns the name of the host

Returns:
the host name

getHostAddress

public java.lang.String getHostAddress()
Returns the IP of the host

Returns:
the host address (IP)

getPort

public int getPort()
Returns the port which this server listens at

Returns:
the port number

allowClientIP

public void allowClientIP(java.lang.String pattern)
Adds an IP address or address pattern for clients acceptable
by this server.

To allow a whole range of IPs, one or more numbers
can be replaced by the asterisk *, e.g. "123.45.*.6"
allows clients with the IPs in range 123.45.0.6 through
123.45.255.6.

Instead of using trailing wildcards, a pattern can be
abbreviated, e.g. instead of "123.45.*.*" you can simply
use "123.45".

Note that it is possible both to allow and to forbid
client IPs.
The possible scenarios are evaluated like this:

If both an allow and a forbid pattern match on a given
        IP, the more specific of the two takes effect.
        (A pattern is more specific, if its leftmost wildcard
        is more to the right than in another pattern.)

        If the allow and forbid patterns are equal, the
        forbid pattern takes precedence: the IP is forbidden.

If only an allow pattern matches,
        the IP is allowed.

If only a forbid pattern matches,
        the IP is forbidden.

If no pattern matches, the outcome depends on the
        existence of allow and forbid patterns:
        If there exist forbid patterns (that don't match
        the IP), the IP is allowed.
        If there are no forbid patterns but allow patterns
        (that don't match the IP), the IP is forbidden.
        If there are no patterns of any kind, access is
        unrestricted: the IP is allowed.
                

Parameters:
pattern - an IP address or a pattern of such
See Also:
forbidClientIP(java.lang.String)

allowClientIPs

public void allowClientIPs(java.lang.String[] pattern)
Adds one or more IP address patterns for clients acceptable by this server.

Parameters:
pattern - an Array of IP addresses or patterns of such
See Also:
allowClientIP(java.lang.String)

forbidClientIP

public void forbidClientIP(java.lang.String pattern)
Adds an IP address or address pattern for clients
not acceptable by this server.

To forbid a whole range of IPs, one or more numbers
can be replaced by the asterisk *, e.g. "123.45.*.6"
allows clients with the IPs in range 123.45.0.6 through
123.45.255.6.

Instead of using trailing wildcards, a pattern can be
abbreviated, e.g. instead of "123.45.*.*" you can simply
use "123.45".

Note that it is possible both to allow and to forbid
client IPs.
The possible scenarios are evaluated like this:

If both an allow and a forbid pattern match on a given
        IP, the more specific of the two takes effect.
        (A pattern is more specific, if its leftmost wildcard
        is more to the right than in another pattern.)

        If the allow and forbid patterns are equal, the
        forbid pattern takes precedence: the IP is forbidden.

If only an allow pattern matches,
        the IP is allowed.

If only a forbid pattern matches,
        the IP is forbidden.

If no pattern matches, the outcome depends on the
        existence of allow and forbid patterns:
        If there exist forbid patterns (that don't match
        the IP), the IP is allowed.
        If there are no forbid patterns but allow patterns
        (that don't match the IP), the IP is forbidden.
        If there are no patterns of any kind, access is
        unrestricted: the IP is allowed.
                

Parameters:
pattern - an IP address or a pattern of such
Since:
1.3
See Also:
allowClientIP(java.lang.String)

forbidClientIPs

public void forbidClientIPs(java.lang.String[] pattern)
Adds one or more IP address patterns for clients not acceptable by this server.

Parameters:
pattern - an Array of IP addresses or patterns of such
Since:
1.3
See Also:
forbidClientIP(java.lang.String)

pleaseStop

public void pleaseStop()
Asks the server to stop working


setVerbose

public void setVerbose(boolean value)
Tells the server to print some accompanying
messages to the console.

Default is off.
                

Parameters:
value - verbose on or off

main

public static void main(java.lang.String[] args)


OCSelot @ www.ocselot.net www.ocselot.net