A Chat System

In this tutorial, we will build a simple, distributed chat system based on RSB.

The initial goal of the first part is having a chat client which sends and receives text messages to and from other clients without the need for a server. A session could look like this:

$ rsb-chat-client
> hi, anyone listening?
other-user: hi, i thought, i was the only one :)
> /quit
$

As an extension, in the second part the chat program should be able to send and receive avatar images to and from other chat clients.

Part 1: Send and Receiving Text Messages

The distributed chat system can be organized by assigning a scope or the form /chat/text/NICKNAME to each participating nickname. This allows receiving messages from a particular sender by listening on /chat/text/NICKNAME and receiving all messages by listening on the superscope /chat/text/.

Implementation-wise, sending and receiving textual chat messages, requires an informer and a listener on the respective appropriate scope:

  • The informer publishes messages on /chat/text/NICKNAME

  • The listener receives all messages on /chat/text/.

    Note

    This includes one’s own published messages, so these have to be filtered out to prevent an “echo” effect.

Part 2: Avatar Images

Avatar images are exchanged between participants of the distributed chat via RSB‘s RPC mechanism. In order to implement this, each chat program

  • creates a local server providing the avatar image of the participant via a method get method under the scope /chat/avatar/NICKNAME.
  • creates a remote server s for downloading avatar images from other participants by calling the methods mentioned above.