kom.tools.ipc
Class IPCServer

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--kom.tools.ipc.IPCServer
Direct Known Subclasses:
SMTPD

public class IPCServer
extends java.lang.Thread

A network server. Once started, the server listens for incoming connections, accepts them and then handles them. The handle method must be overriden in subclasses.


Field Summary
 int port
          Port number for listening (default 80)
protected  java.net.ServerSocket socket
          Socket for incoming connections
 
Fields inherited from class java.lang.Thread
contextClassLoader, daemon, eetop, group, inheritedAccessControlContext, MAX_PRIORITY, MIN_PRIORITY, name, NORM_PRIORITY, priority, single_step, stillborn, stopThreadPermission, target, threadInitNumber, threadQ, values
 
Constructor Summary
IPCServer()
          default class constructor
IPCServer(int p)
          Class constructor
 
Method Summary
protected  IPCConnection accept()
          Waits for a connection (blocks until a client tries to connect)
protected  boolean bind()
          Binds the server to the specified port
 void handle(IPCConnection connection)
          This is a deferred method for handling an incoming connection.
 void run()
          Overriden method.
 void start()
          Starts a thread (overriden method).
 
Methods inherited from class java.lang.Thread
, activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, exit, getContextClassLoader, getName, getPriority, getThreadGroup, init, interrupt, interrupt0, interrupted, isAlive, isDaemon, isInterrupted, isInterrupted, join, join, join, nextThreadNum, registerNatives, resume, resume0, setContextClassLoader, setDaemon, setName, setPriority, setPriority0, sleep, sleep, stop, stop, stop0, suspend, suspend0, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

port

public int port
Port number for listening (default 80)

socket

protected java.net.ServerSocket socket
Socket for incoming connections
Constructor Detail

IPCServer

public IPCServer()
default class constructor

IPCServer

public IPCServer(int p)
Class constructor
Parameters:
p - the port number for listening
Method Detail

accept

protected IPCConnection accept()
Waits for a connection (blocks until a client tries to connect)
Returns:
The connection or null.

bind

protected boolean bind()
Binds the server to the specified port
Returns:
true if operation was ok or false if an error occurs

start

public void start()
Starts a thread (overriden method). Bind the server to the specified port.
Overrides:
start in class java.lang.Thread

run

public void run()
Overriden method. There is an infinite loop with two actions: accept and handle. That is: wait for a connection and then process it.
Overrides:
run in class java.lang.Thread

handle

public void handle(IPCConnection connection)
This is a deferred method for handling an incoming connection. A subclass must override this method. The handle here only closes the incoming connection.
Parameters:
connection - the incoming connection from the client