This zip file contains the source and Java class files for an example of a Telnet server. I built this as an example for a company that needs to build a TL1 server, so lines are terminated by semicolons rather than carriage-returns, but that's easy to change.
To test the app, unload the files into a directory. then run:
java AppDeamon
from that directory (on a PC you need to run it from a DOS prompt window).
The config.dat file sets the socket number, in the default example it's 8191. So, next fire up a telnet program and connect to 127.0.0.1 port 8191. If the program is running properly you should see in the Telnet client:
Welcome to the CLient-Server demo
Typing "?;" will respond with the known commands:
I can respond to ?, act-user, date, and canc-user...
Try typing "date;" - since you haven't logged in it should respond:
User not validated! Command not processed!
Not type in "act-user;" - it should respond
User logged in!
Now try the "date;" command! You should see:
does anyone really know what day it is?
Leaving that telnet session for a moment, bring up a few more telnet sessions and try it. They all should work.
Finally, log out via "canc-user;"
The classes and their basic functions are:
Class | Function |
AppDeamon | This class is derived from TelnetDeamon and processes the commands recieved from the user. With any luck, this is the only class you need to modify to recieve and execute commands. |
TelnetDeamon | This is the abstract base class that sets up the socket and creates the TelnetThread. You shouldn't need to modify this class |
Configuration | This is a simple class that parses the config.dat file. |
TelnetThread | This thread handles the Telnet protocol and communications to the telnet client.Two useful RFCs to understand how Telnet works is the Telnet RFC, and the Terminal Type RFC. You shouldn't need to modify this class |