XML-Based Java Chat Client
The purpose of this assignment was to:
- Learn how to use a high-level technique for accessing XML documents
- Learn how to write protocols by using XML documents defined by DTDs
The description and my solution of the XML-Based Java Chat Client - assignment can be viewed at the bottom of this page.
What is a protocol?
A protocol is a formal description of message formats and the rules that two computers must follow in order to exchange those messages in their communication.
How to write a protocol in XML
One has to come up with elements and attributes for structuring the information that should be used in the communication, and then use a DTD or XSD to define and constrain those elements and attributes.
Assignment Description
Create a Java Chat Client that uses an XML-based protocol constrained with message.dtd.
-
When sending a message:
- Use class Document(org.jdom.Document) to create a XML document that uses the public DTD-filen message.dtd.
- Use class XMLOutputter(org.jdom.output.XMLOutputter) to format the XML-dokumentet to a long string without line breaks before sent to a XML-based Java Chat Server.
-
When receiving a message:
- Use class SAXBuilder(org.jdom.input.SAXBuilder) to validate and to create a Document object.
- Use the Document object to access the specific parts of the XML document that should be displayed to the user; <name>, <email> and <body>
Use either JDOM or JAXP package.
My solution, Assignment Files
I chose to use JDOM.
To try the Chat Client you first need to create a XML-based Java(or any other programming language) Chat Server. The teacher for this course already had one created so that we could try our Chat Clients. Since I'm not sure he wan't me to make the address for this server public, you will have to create your own XML-based Chat Server to try the XML-based Java Chat Client.
You could, however,do some changes to the Java Chat Server from the Internet Programming 1 Course to make it XML-based.
To run the Chat Client:
Unix/Linux: java -classpath jdom.jar:. Chat
Win32: java -classpath jdom.jar;. Chat
When you've downloaded and compiled the .java files below, you've got to put jdom.jar in your classpath.
XML-Based Java Chat client source files:
-
Chat.java
The main-method and GUI class. -
Sender.java
The class taking care of the creating and sending of messages. -
Receiver.java
The class taking care of the receiving of messages. -
manifest.txt
Manifest file -
message.dtd
The DTD file used for defining the rules of the message protocol.
