Package biz.chitec.qdemo.chat.server
GChat - a small GJSA server application.
See:
Description
Package biz.chitec.qdemo.chat.server Description
GChat - a small GJSA server application.
Package Specification
This package contains the GChat server application. Explore the files in the following order:
- QJChatServer.java is the main server application. It contains some
small parts of business logic. Mainly, it is responsible for sending the
messages as it is the only class that is known to all client-serving
threads.
- ChatLoginExecutor is a small executor that is launched for each newly
opened connection. It accepts the CHATLOGIN command only and launches
another executor when it is issued.
- DoChatExecutor is the one being responsible for actual chatting.
All source files do have extensive Javadoc documentation and lots of additional comments
in the source code itself.
Running the server
Ensure that the appropriate path for the chitec-gjt sources is in your
CLASSPATH. You should then be able to compile the demo, e.g. by using the
cj compilation script (or by issuing javac or jikes to the
.../org/gjt/chitec/demo/gchat
directory. After that, you have the GChat server ready.
Start the server with
java org.gjt.chitec.demo.gchat.server.QJChatServer
When it comes up for the first time, it will need some seconds to compute
an RSA key pair. When it prints "*** NOW READY TO ACCEPT CONNECTIONS ***",
have two telnet windows at your hands.
Connect through "
telnet localhost 51000
". Issue the command
CHATLOGIN "anyname"
in exactly that spelling and with the quotation marks ("). Look how the
server logs all of your commands. Now, you can send messages to the chat
server which will propagate them to all connected clients. As there is only
one client connected, use the second terminal window to connect with
another telnet as other user. Note that you have to use a different name
with the CHATLOGIN command from the second telnet as the server does not
allow two chatters with the same name.
Now you can see how your messages appear on both clients when you type them in...
Extending the server
Now, let's suppose you want to add a new command. Say, a command that gives
you the last ten messages sent through the system. These would be the
steps:
- First, add business logic in QJChatServer. You would need a storage for
the messages, attach a mechanism to the sendChatMessage() method that feeds
the storage and a supposed getLastMessages() method that returns the
content.
- Now decide on your command's name. Let name it "GETLASTMESSAGES".
- Add that symbol together with a unique number to GChatRequestSymbols.cmds. Order is irrelevant.
- Run the preprocessor, best through the "cj" script. It will create the java file.
- Now add the handler to the switch-case-construct of the appropriate CommandExecutor. in this case, it is DoChatExecutor, as you want to
have to command available after login of the user.
- Recompile, run, be happy.
- Author:
- chitec/Dirk Hillbrecht 2001
- See Also:
org.gjt.chitec.demo.gchat.util
,
org.gjt.chitec.demo.gchat.client