Assignment 2: A Notification Server

In Assignment 1 (up to phase 3), you began by putting together a simple chat server. It did very little aside from pushing out chat messages to all connected clients. In this assignment, you will be building a notification server--this is a server that connects people with other people, as well as data. By the end of this assignment, your notification server (and the associated client) will support drawing, as well as interaction with another bot that brings in external data such as the weather.

Note: This is a fairly involved assignment, and though I think you will be very happy with the end result.

To help you work through this assignment, here are the basic scaffolded steps:

  1. Part 1: Implement a simple protocol on the server
  2. Part 2: Build a simple client in C#
  3. Part 3: Implement "Direct Messages"
  4. Part 4: Create a bot that relays information from an external service

Part 1: Implement a simple protocol

By the end of this part, you will:

You can begin with the server3.js from Assignment 1.

The basic protocol will use JSON objects (fortunately, we won't worry about serialization too much). Your protocol should handle three basic message types:

Basic Text Message

{
  "messagetype": "textmessage",
  "content": "hello",
  "username": "tony"
}

Basic Login/Logout Message

// action can be: login or logout
{
  "messagetype": "client",
  "action": "login",
  "username": "tony"
}

Draw Message

// x1,x2,y1,y2 are integers
// username: the person that did the drawing
{
  "messagetype": "draw",
  "x1": 12,
  "y1": 100,
  "x2": 15,
  "y2": 100,
  "username": "tony"
}

You will need to slightly redesign your server so that it is a Javascript object that makes use of the EventEmitter class, and so that it can fire events.

When you receive these different kinds of messages, fire an event (i.e. emit('textmessage', ...), emit('client', ...), etc.).

Redo your logging mechanism so that it uses these events (i.e. on('textmessage', ...), on('textmessage', ...)). The logger can be straightforward (i.e. dump to console, with the ability to turn it on or off); just demonstrate that you can do the publish/subscribe pattern and use the entities inside the json messages.

Your server should not barf on poorly constructed messages; instead, it should log these messages and otherwise ignore them. In the general case, this would be it; however, for the purpose of this assignment, pass these poorly constructed messages on to the clients.

In this case, we are doing very little with thie publish/subscribe pattern. In principle, one reason you might design your server in this way is to allow easy extensibility (plugins, etc.).

Hints

It will be useful to read up on how to use the EventEmitter class. I found some of the binding issues to be a bit troublesome, so I have included a Notification Server template that you can use.

"Object-oriented" programming in Javascript is a bit funky. But you don't have to do much in this case. Just wrap most of the code you wrote for server3.js into a class called NotificationServer.

To test the functionality of your server, you may consider using these tools so that you are sending your server well-constructed JSON messages:

Part 2: Build a simple client in C#

Build a simple client in C# that responds to messages from and sends appropriate messages to the server via the protocol.

Sweet sketch of a mocked up client UI

The client should report when someone has logged in or logged out, allow the reception of text messages (and sending of them). It should interpret the draw messages by drawing in the canvas. Finally, you should allow a person to sketch on the canvas by dragging their mouse.

In relation to malformed messages from the server:

Other situations:

Hints

Part 3: Direct Messages

Create a mechanism that allows for people to send messages directly to another recipient connected to the server. That is, you should be able to direct a message to only one recipient.

You may want to modify your server so that it only sends these messages to the intended recipient.

You can do this in a number of different ways: some involve modifying the UI and/or the protocol; others could involve shorthand akin to what one might see on Twitter, etc. There are a bunch of trade-offs depending on how you do it. Make sure that you are able to identify these trade-offs and justify your choice.

Part 4: Creating a Bot

Create a bot that can connect to your server. Its role is to bring in external information, and pass it along to whomever requested it. As a user connected to the "chat", a person should be able to send a message to the bot to request information somehow, and customize that information somehow. The kind of information that you pull in is up to you. Be creative!

Hints:

Some examples of bot ideas:

Some additional packages might be useful:

Part 5 (optional): Bonus

In computer systems, a common problem is that we lack an awareness of what others are doing in the system. In real life, we do not lack this awareness. For instance, if you and I were both writing on the whiteboard, I can see that you are writing, and would be unlikely to bump into you or start drawing where you are. We generally lack this awareness in computer systems that have not been explicitly designed to support this.

In this part, build awareness support by providing feedthrough of people's actions in the system in at least two different ways:

Hints:

References