This page uses CSS styles
Project work within an OBP course on CTU FEL, Prague
Distributed chat in Smalltalk compatible with Java version
Oto Válek
CTU FEL Prague, summer term 2001/2002, classes on Tuesday 9:15 am
1. Summary
This is a Smalltalk (Visual Works) application, implementing a simple distributed
chat. Therefore, no central server is needed for user communication.
The chat is compatible with existing
Java version, using a subset
of its communication protocol.
2. Quick user reference
First use the Setup button to choose your nickname.
You may wish to change the default value of port (6060).
Either press Connect to connect to other user
(enter his hostname or IP) or just wait for an incoming connection.
During conversation, observe the list of other users on the right.
At the end, use the Disconnect button. You may now
join an other user or stop accepting incoming connection by pressing
Close. Closing the main window does that automatically.
3. Running the application
The application is stored in a image file.
To run it on your system with VisualWorks, use
visual chat.im
You may also load parcel chat.pcl or source and execute
Chat open
4. Application architecture overview
The application consists of 5 classes in Valeko category. Each non-trivial method has a short
description of its purpose as a comment. TCP socket communication is provided
by classes in NetClients parcels. Distribution image has been created with
the RuntimePackager wizard.
Chat
|
Main application class.
Maintains references to other objects using "lazy initialization".
Holds a list of open interfaces so that it may change their window titles
and add lines to the main text area.
The changeRequest
method is overriden to detect window closing and close listening port.
Contains several methods, that Sender and
Receiver use to update user interface.
|
Receiver
|
Starts a server listening on the given port, which receives and processes
messages in the background thread
(forkAt: method of a block).
There's a method for each protocol message.
Each protocol message received is passed to all methods, which process
only the particular one.
|
Sender
|
Handles outgoing TCP connections - attaches application to the network and send
protocol messages to other users from the HostList
and the MESSAGE message also to himself.
TCP errors, such as timeouts, are caught and
result in the removal of the remote user from the
HostList.
|
HostList
|
Implements a user list using a Dictionary collection
accessed by nickname and containing HostItem items.
It uses dependency mechanism to notify the Chat
class of any changes, allowing it to update the list in dialog.
Also stores information about my identity (nick, IP, port).
Its contents are accessed using methods returning various ordered collections.
|
HostItem
|
Holds information about one user : nickname, IP and port. It is able to
print its contents to a stream.
|
|
5. Communication protocol
Communication protocol is character and line based, like many othes TCP using
protocols (HTTP, TCP). Every command is handled in separate TCP connection
and is followed by newline character.
Unless otherwise noted, command reception is acknowledged by
OK response followed by newline character.
A list of commands follows:
GET
|
Request for the user list. Command is sent by a new member before the
CONNECT command. Host responds with the list of
ITEM <nick> <host> <port>
lines terminated by the OK line.
|
CONNECT <nick> <host> <port>
|
Connection to the network. A new member sends this message to users acquired
with GET command and anounces its identification.
Others will add the new user to their user lists.
|
MESSAGE <nick> <host> <port> <text>
|
A text message. A sender sends it to all the users, including himself.
If the receiver doesn't know the sender, he stores him to his user list.
|
FILE <nick> <host> <port> <name> <size>
|
Not implemented and ignored.
|
DISCONNECT <nick>
|
Disconnection from the network. A sender sends it to all the users, excluding himself.
|
|
6. Files
Attached file:
chat.zip - ZIP archive of the image, parcel, source and this manual