to.etc.telnet
Class TelnetServer

java.lang.Object
  extended by to.etc.telnet.TelnetStateThing
      extended by to.etc.telnet.TelnetServer
All Implemented Interfaces:
java.lang.Runnable

public class TelnetServer
extends TelnetStateThing
implements java.lang.Runnable

Implements a Telnet server for log and debugging tasks. Each session started can send and receive data. Each session will get a separate thread(!) so this is NOT meant as a serious implementation! To get a working server call the static method createServer; this will create a server structure and it's associated thread, called the listener thread. The only task of this thread is to listen for new session requests and to spawn new sessions when these occur.

Author:
Frits Jalvingh

Field Summary
 
Fields inherited from class to.etc.telnet.TelnetStateThing
tsDOWN, tsINITING, tsNONE, tsRUN, tsSHUT
 
Method Summary
 void _write(byte[] ar, int off, int len)
           
 void _write(int ch)
          Called to dump data from outputstream and such..
 void addCommandHandler(ITelnetCommandHandler tch)
          Adds a command handler.
static TelnetServer createServer(int port)
          Creates a new Telnet server.
protected  void executeTelnetCommand(TelnetPrintWriter tpw, java.lang.String command)
          Calls a command handler for a given (session, command) to get it executed.
static void main(java.lang.String[] args)
           
static void registerTelnetCommand(ITelnetCommandHandler tch)
           
 void run()
          This is the server's thread.
protected  void sessionClosed(TelnetSession ts)
          Called to remove a session that was closed (due to error or normal circumstances) from this server's tables.
static void startTelnetServer(int port)
          Called to start the telnet server.
 void wall(java.lang.String msg)
          Sends a single string to ALL clients.
 
Methods inherited from class to.etc.telnet.TelnetStateThing
getState, getStateString, inState, setState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createServer

public static TelnetServer createServer(int port)
                                 throws java.lang.Exception
Creates a new Telnet server.

Throws:
java.lang.Exception

addCommandHandler

public void addCommandHandler(ITelnetCommandHandler tch)
Adds a command handler.


executeTelnetCommand

protected void executeTelnetCommand(TelnetPrintWriter tpw,
                                    java.lang.String command)
Calls a command handler for a given (session, command) to get it executed.


run

public void run()
This is the server's thread. It blocks on accept() on the server socket and accepts new connections. When a new connection is established a new session is started for that connection (using a new thread) and we loop again. On error the server will enter down state.

Specified by:
run in interface java.lang.Runnable

sessionClosed

protected void sessionClosed(TelnetSession ts)
Called to remove a session that was closed (due to error or normal circumstances) from this server's tables.


wall

public void wall(java.lang.String msg)
Sends a single string to ALL clients. The string gets locally buffered if required.


_write

public void _write(int ch)
Called to dump data from outputstream and such..


_write

public void _write(byte[] ar,
                   int off,
                   int len)

main

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

startTelnetServer

public static void startTelnetServer(int port)
Called to start the telnet server. If the server has already started this returns false.


registerTelnetCommand

public static void registerTelnetCommand(ITelnetCommandHandler tch)