Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c914bbb
added basic structure
Jamesbillard12 Jul 25, 2017
a21bdda
Merge pull request #1 from Jamesbillard12/james-server
Jamesbillard12 Jul 25, 2017
ba5ef47
added nickname feature
Jamesbillard12 Jul 25, 2017
f6972c2
added in helpMe
Jamesbillard12 Jul 25, 2017
3354333
fixed typo in help me
Jamesbillard12 Jul 25, 2017
ca10bc6
added rainbowcat to readme
Jamesbillard12 Jul 25, 2017
be4a20b
working on readme
Jamesbillard12 Jul 25, 2017
9df3233
Merge pull request #2 from Jamesbillard12/james-server
Jamesbillard12 Jul 25, 2017
f94567c
cat
Jamesbillard12 Jul 25, 2017
0d56f97
added img?
Jamesbillard12 Jul 25, 2017
3269041
now fixed
Jamesbillard12 Jul 25, 2017
208b4d3
removed img
Jamesbillard12 Jul 25, 2017
f389826
Merge pull request #3 from Jamesbillard12/james-server
Jamesbillard12 Jul 25, 2017
a51494f
added to read me
Jamesbillard12 Jul 25, 2017
47dfd50
edited readme help menu
Jamesbillard12 Jul 25, 2017
4e357f0
more readme edits
Jamesbillard12 Jul 25, 2017
db2ee43
yet another readme edit
Jamesbillard12 Jul 25, 2017
a5aae0d
and again
Jamesbillard12 Jul 25, 2017
47f2607
added markdown
Jamesbillard12 Jul 25, 2017
f97f948
think i fixed it
Jamesbillard12 Jul 25, 2017
4c1e821
finally fixed it
Jamesbillard12 Jul 25, 2017
cf46852
Merge pull request #4 from Jamesbillard12/readme
Jamesbillard12 Jul 25, 2017
fcdaa24
indentation
Jamesbillard12 Jul 25, 2017
160d5eb
Merge pull request #5 from Jamesbillard12/readme
Jamesbillard12 Jul 25, 2017
14a79a0
deleted unused param
Jamesbillard12 Jul 25, 2017
bbaaf89
Added some error handling for changing nickname
Jamesbillard12 Jul 25, 2017
c3b35b2
Added solutions to all error cases
Jamesbillard12 Jul 25, 2017
4869e74
Added color to Help comand
Jamesbillard12 Jul 25, 2017
e8bd1f4
added error blocks
Jamesbillard12 Jul 25, 2017
dc63f9e
added eslint-disable to lib file
Jamesbillard12 Jul 25, 2017
9765b33
Merge pull request #6 from Jamesbillard12/errors
Jamesbillard12 Jul 25, 2017
e1b7f32
fixed errors in err
Jamesbillard12 Jul 25, 2017
149db02
Merge pull request #7 from Jamesbillard12/master
Jamesbillard12 Jul 25, 2017
f11ea40
Merge pull request #8 from Jamesbillard12/errors
Jamesbillard12 Jul 25, 2017
c96cc6c
I think i finally fixed it this time
Jamesbillard12 Jul 25, 2017
eb4f36a
Merge pull request #9 from Jamesbillard12/new-errors
Jamesbillard12 Jul 25, 2017
dab4a92
fixed @all
Jamesbillard12 Jul 26, 2017
6e4ef0f
Merge pull request #10 from Jamesbillard12/new-errors
Jamesbillard12 Jul 26, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/node_modules/*
**/vendor/*
**/*.min.js
**/coverage/*
**/build/*
21 changes: 21 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"rules": {
"no-console": "off",
"indent": [ "error", 2 ],
"quotes": [ "error", "single" ],
"semi": ["error", "always"],
"linebreak-style": [ "error", "unix" ]
},
"env": {
"es6": true,
"node": true,
"mocha": true,
"jasmine": true
},
"ecmaFeatures": {
"modules": true,
"experimentalObjectRestSpread": true,
"impliedStrict": true
},
"extends": "eslint:recommended"
}
136 changes: 136 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Created by https://www.gitignore.io/api/osx,vim,node,macos,windows

### macOS ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env


### OSX ###

# Icon must end with two \r

# Thumbnails

# Files that might appear in the root of a volume

# Directories potentially created on remote AFP share

### Vim ###
# swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-v][a-z]
[._]sw[a-p]
# session
Session.vim
# temporary
.netrwhist
*~
# auto-generated tag files
tags

### Windows ###
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.gitignore.io/api/osx,vim,node,macos,windows
76 changes: 33 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,38 @@
![cf](https://i.imgur.com/7v5ASc8.png) Lab 06: TCP Chat Server
James' Chat Server
======

## Submission Instructions
* fork this repository & create a new branch for your work
* write all of your code in a directory named `lab-` + `<your name>` **e.g.** `lab-susan`
* push to your repository
* submit a pull request to this repository
* submit a link to your PR in canvas
* write a question and observation on canvas
This project creates a simple TCP chat room using Node leveraging the 'net' module. Any number of users can connect to the chat room and communicate with one another. The Node 'net' module allows a developer to create any kind of TCP server and, in this case, handle simple user input and output based on the data received. This program first creates a Client through a Client Constructor and uses NPM uuid to generate unique universal ids for each client. The simplest method to connect to the chat server is telnet, built into most operating systems in some form. Although, many other similar TCP clients exist. The server can respond to the following user "@" commands by parsing the text at the beginning of a line of text sent by a user:

## Learning Objectives
* students will understand how to implement a TCP server using the `net` module
* students will understand how to work with node.js EventEmitter's
```
.......................................................................
. o \ o / _ o __| \ / |__ o _ \ o / o .
. /|\ | /\ __\o \o | o/ o/__ /\ | /|\ .
. / \ / \ | \ /) | ( \ /o\ / ) | (\ / | / \ / \ .
.......................................................................
. cmd: '@FML' to view help instructions. .
. cmd: '@all <msg>' to send a message to everyone in chat. .
. cmd: '@dm <name> <msg>' to private message another user. .
. cmd: '@nickname <name>' to change your name. .
. cmd: '@quit' to exit chat room. .
.......................................................................
```

## Requirements
#### Configuration
<!-- list of files, configurations, tools, etc that are required -->
Your lab directory must include
* `.gitignore`
* `.eslint`
* `package.json`
* `README.md`
# The following are basic instructions:
## Start the server:
#### Requirements: Node is installed and navigated to the working directory of the chat room application.
## Instructions:
```
npm I
```
gets all dependencies.
```
npm run start
```
starts the server.

#### Feature Tasks
* create a TCP Server using the NodeJS native `net` module
* create a `Client` Constructor
* when sockets connect to the server, a new `Client` instance should be made
* all clients should have a unique `id` property - this should come from the use of `node-uuid`
* when sockets are connected with the client pool they should be given event listeners for `data`, `error`, and `close` events
* when a socket emits the `close` event, the socket should be removed from the client pool
* when a socket emits the `error` event, the error should be logged on the server
* when a socket emits the `data` event, the data should be logged on the server and the commands below should be implemented

## Custom commands
* `@all` should trigger a broadcast event
* `@nickname` should allow a user change their nickname
* `@dm` should allow a user to send a message directly to another user by nick name or by their guest id _(unique client id)_
* when a user sends a message, their nickname should be printed
* **i.e.** `cfcrew: sup hackerz`

#### Documentation
* write a paragraph about your project
* write documentation on how to get the project running
* write documentation on how to connect to the server

#### Testing
* no testing required for this lab - yay!
## Connect to the server:
Requirements: A client, such as telnet, is installed and the IP or hostname of the server is known.
Instructions: ex
```
telnet 127.0.0.1 3000
```
8 changes: 8 additions & 0 deletions model/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';
const uuidv4 = require('uuid/v4');

const Client = module.exports = function(socket){ // eslint-disable-line
this.socket = socket;
this.nickname = `user_${Math.round(Math.random() * 1000000)}`;
this.id = uuidv4;
};
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "06-tcp_servers",
"version": "1.0.0",
"description": "![cf](https://i.imgur.com/7v5ASc8.png) Lab 06: TCP Chat Server ======",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Jamesbillard12/06-tcp_servers.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/Jamesbillard12/06-tcp_servers/issues"
},
"homepage": "https://github.com/Jamesbillard12/06-tcp_servers#readme",
"dependencies": {
"colors": "^1.1.2",
"uuid": "^3.1.0"
}
}
Loading