CPSC 599.81 Assignment 1

In this first assignment, you will build a very simple chat system in a phased approach.

Phase 1: Simple Chat Server

Create a TCP server that listens on port 8113 (you'll want to use net.createServer(...)). The server should track each connection. For each message (a string delimited by a newline) that the server receives, it sends it out to every connected client. Save this as server1.js.

Hints

Phase 2: Add "username" to the chats

Most chat systems allow a person to have a username. Usually, messages from people are prepended with the username, too. For example:

Jill: I love this chat system

Larry: Tell me about it

Create server2.js such that the first string that a client enters is his/her username, and that when s/he sends a message, the message is prepended with his/her username.

Phase 3: Add a logging mechanism

Build a simple logging mechanism into the server that logs messages that go through the server. The logger should have at least three different levels (see below). The logger should log to the console, as well as to a specified file. If a file is not specified, then the system should only log to the screen. If no logging level is specified, then it should default to level 0.

  1. Level 0: No logging
  2. Level 1: Logs only messages with the following format: [date-time] MESSAGE: [username]: [message]
  3. Level 2: Logs also the connections and disconnects from the clients: [date-time] [CONNECT/DISCONNECT]: [IP]:[port]

You should be able to call your app using the following calling conventions:

node server3.js -l 2 -f chat.log

node server3.js --log-level=2 --file=chat.log

node server3.js -l 1

node server3.js -f chat.log #this shouldn't do anything, because the default log level is 0

Hints

Phase 4: Eliza server

ELIZA was an early example of natural language processing. It basically acted as a poor-man's psychiatrist. You can give it a try. Don't spend more than 5 minutes getting therapy! ;-)

In this phase of the project, you will be responsible for integrating an elizabot into your chat server, elizaserver.js. Each connection should get its own instance of Eliza (so multiple people connecting at the same time should not confuse Eliza).

Hints

Phase 5 (optional): Elizabot chat client

In this phase, the idea is to use your knowledge of the Eliza implementation, and build a client. The client connects to your server server3.js, and basically talks with everyone that connects to the server. For extra fun, you can build two versions of this: one version that only spawns one instance of Elizabot and talks to everyone, and one version that spawns an independent instance of Elizabot for each connection to the server. In this latter version, in ElizaBot's replies, you'll probably need to prepend her responses with something like, "Tony, " to make it clear who she's talking to.

Hints