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"
}

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"
}

Handle these different message types using a different events (i.e. on('textmessage', ...), on('client', ...), etc.).

Redo your logging mechanism so that it uses these events.

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.

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:

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:

References