In this first assignment, you will build a very simple chat system in a phased approach.
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
data
, close
.data
event when someone presses enter.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.
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.
[date-time] MESSAGE: [username]: [message]
[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
npm-getopt
package to help you parse the command line arguments.socket.remoteAddress
and socket.remotePort
propertiesELIZA 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
require
statement. You will also likely need to include the data file into this module.node-inspector
to help you debug, or if you're really into printf
-style debugging, you will likely fine console.info()
to be helpful.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
net.createServer(...)
, look into using net.createConnection(...)
.