Main Page   Class Hierarchy   Compound List   File List   Compound Members  

ConnectionServer Class Reference

Collaboration diagram for ConnectionServer:

Collaboration graph
[legend]
List of all members.

Detailed Description

ConnectionServer.java defines objects which are responsible for handling single, remote connection to your application.

This class listening on Socket and waiting for your command, puts given String to all command handlers and sends back to user through the net.

Instance of this class is created by ConnectionHandlerImpl after receiving new connection request in SocketListener. It contains one own implementation of CommandHandlerIfc for handling some sort of internal command such as 'quit', 'help', 'who' and so on...

At the moment command shel is very simple but it is possible to add command history feature, more inteligent input, shortcut for last command and so on.

Created: Thu Jan 10 16:35:05 2002

Author:
Artur Hefczyc
Version:
Revision
1.1

Definition at line 66 of file ConnectionServer.java.

Public Methods

 ConnectionServer (Socket socket, List command_handlers) throws IOException
 Creates a new ConnectionServer instance and setting up connection to client.

void run ()
 run method handles all user inputs and sends commands output back to user.


Protected Methods

void asyncMessage (String msg)
 asyncMessage method was added for support asynchronously sending messages from server to all connected clients.

boolean processCommand (String line)
 processCommand method hadles processing command actions.

void log (String msg)
 log method is simple logging method.


Protected Attributes

Socket my_socket = null
 Variable my_socket keeps socket for this active connection.

BufferedReader inst = null
 Variable inst keeps input strean from user indeed.

PrintWriter out = null
 Variable out is output stream de-facto.

List comm_handl = null
 Variable comm_handl is a List keeping all available command handlers.

LogIfc log_impl = null
 Variable log_impl contains reference to logging class implementation.

boolean prompt = true
 Variable prompt is a switch which tell me whenever to print command prompt or not.

boolean echo = true
 Variable echo simple switch which tells me if I am in 'echo' mode on or off.


Static Protected Attributes

List active_connections
 This static variable active_connections contains list of all active connections at the time.


Constructor & Destructor Documentation

ConnectionServer Socket    socket,
List    command_handlers
throws IOException [inline]
 

Creates a new ConnectionServer instance and setting up connection to client.

At the and it prints command prompt and waits for user input.

Parameters:
socket a Socket value
command_handlers a List value
Exceptions:
IOException if an error occurs

Definition at line 153 of file ConnectionServer.java.


Member Function Documentation

void asyncMessage String    msg [inline, protected]
 

asyncMessage method was added for support asynchronously sending messages from server to all connected clients.

Please beware of using this feature.

Your application may not know how many remote consoles are active and in what states are they. But if you use this method you will send asynchronously message to connected client. It is application responsibility to not send asyncMessage during command processing.

Parameters:
msg a String value is a massage which must be sent to connected client.

Definition at line 235 of file ConnectionServer.java.

void log String    msg [inline, protected]
 

log method is simple logging method.

Parameters:
msg a String value

Definition at line 267 of file ConnectionServer.java.

boolean processCommand String    line [inline, protected]
 

processCommand method hadles processing command actions.

Searches all command handlers and passes to them received command string. As a result prints back to user commands handlers results.

Parameters:
line a String value
Returns:
a boolean value

Definition at line 247 of file ConnectionServer.java.

void run   [inline]
 

run method handles all user inputs and sends commands output back to user.

Definition at line 177 of file ConnectionServer.java.


Member Data Documentation

List active_connections [static, protected]
 

Initial value:

    Collections.synchronizedList(new ArrayList())
This static variable active_connections contains list of all active connections at the time.

It allows to list all active connections by any user and allow to close active connection which is not used anymore.<br/> Next version I am going to add simple messages system to allow communicate between users on different connections. I am not sure if it is really needed.

Definition at line 75 of file ConnectionServer.java.

List comm_handl = null [protected]
 

Variable comm_handl is a List keeping all available command handlers.

Every command received from user is handled against all available command handlers. So it is very likely that if more than one command handler has defined handler for given command output will be summed - concatenated String containing all responses given from all command handlers. So be aware of defining new handlers for existing commands. To tell you the true it many cases it can be useful.

Definition at line 106 of file ConnectionServer.java.

boolean echo = true [protected]
 

Variable echo simple switch which tells me if I am in 'echo' mode on or off.

In general echo mode on is required for use Remote Console with MSWindows 'telnet'.

Echo mode on is default because with out it, working with MSWin is almost impossible.<br/> On the other side there is CygWin project which provides Unix like environment under MSWin and his 'telnet' which generally doesn't require echo from remotecons. But it is not a problem when it is switched on. You can get only your own imput as extra response from the server.

I don't know how other 'telnets' works from other systems.

Definition at line 142 of file ConnectionServer.java.

BufferedReader inst = null [protected]
 

Variable inst keeps input strean from user indeed.

I perform char by char reading from this stream in echo mode on and line reading in echo mode off.

Definition at line 90 of file ConnectionServer.java.

LogIfc log_impl = null [protected]
 

Variable log_impl contains reference to logging class implementation.

It is possible, however not fully implemented, to define by user new log handler and put it to ConnectionServer to allow logging some info to choosen place.

Definition at line 113 of file ConnectionServer.java.

Socket my_socket = null [protected]
 

Variable my_socket keeps socket for this active connection.

Maybe it is not necessary for doing his work by ConnectionServer since it communicate with user through input/output streams taken from the socket but at the moment I use it for extracting some connection info such as remote/local IP numbers and adresses.

Definition at line 84 of file ConnectionServer.java.

PrintWriter out = null [protected]
 

Variable out is output stream de-facto.

All output to user is written to this output. Additionally in echo mode on user input is sent back to this output stream too.

Definition at line 96 of file ConnectionServer.java.

boolean prompt = true [protected]
 

Variable prompt is a switch which tell me whenever to print command prompt or not.

In general I shouldn't print command prompt when previous command processing is not finished yet. For example command handlers require additional info to complete command. At the moment there is only one such command: 'exit' which require user comfirmation: 'yes' or 'no' answer. I detect it by checking end of String given from command handler. If it ends with '
' sequence it means for me that command processing is finished, if not I assume that processing is in progress.

Definition at line 124 of file ConnectionServer.java.


The documentation for this class was generated from the following file:
Generated on Thu Dec 19 21:00:47 2002 for WTTools - Remote Console by doxygen1.3-rc2