-
Notifications
You must be signed in to change notification settings - Fork 13
Aliza tcp #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aliza89p
wants to merge
6
commits into
sea-401d5-javascript:master
Choose a base branch
from
aliza89p:aliza-tcp
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Aliza tcp #8
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bcacaf4
initial commit. Got remote port to display as username
aliza89p d78dbd2
changed to clients
aliza89p 102375e
working on testing
aliza89p 99a506a
figuring out testing
aliza89p 6ad1f45
created new variable
aliza89p f2d919c
fixed test
aliza89p File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| const gulp = require('gulp'); | ||
| const eslint = require('gulp-eslint'); | ||
| const mocha = require ('gulp-mocha'); | ||
|
|
||
| gulp.task('default', ['lint', 'mocha'], () => { | ||
| console.log('default for lint and mocha'); | ||
| }); | ||
|
|
||
|
|
||
| gulp.task('lint', () => { | ||
| gulp.src('/*.js') | ||
| .pipe(eslint({})) | ||
| .pipe(eslint.format()) | ||
| }); | ||
|
|
||
| gulp.task('mocha', () => { | ||
| gulp.src('test/test.js') | ||
| .pipe(mocha()); | ||
| }); | ||
|
|
||
| gulp.watch('./*.js', ['lint', 'mocha']); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "name": "aliza", | ||
| "version": "1.0.0", | ||
| "description": "tcp server lab", | ||
| "main": "tcp_server.js", | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1" | ||
| }, | ||
| "author": "", | ||
| "license": "ISC", | ||
| "devDependencies": { | ||
| "chai": "^3.5.0", | ||
| "eslint": "^2.10.2", | ||
| "gulp": "^3.9.1", | ||
| "gulp-eslint": "^2.0.0", | ||
| "gulp-mocha": "^2.2.0", | ||
| "mocha": "^2.4.5" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| const net = require('net'); | ||
|
|
||
| const client = net.connect(3000, () => { | ||
| // client.on('data', (data) => { | ||
| // client.write('MESSAGE RECEIVED'); | ||
| // }) | ||
| client.write('HERE IS MESSAGE'); | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| const net = require('net'); | ||
|
|
||
| const clients = []; | ||
|
|
||
| module.exports = exports = net.createServer((socket) => { | ||
| socket.name = socket.remotePort; | ||
| clients.push(socket); | ||
| socket.on('data', (chunk) => { | ||
| console.log(chunk.toString()); | ||
| socket.write('Sending message\n'); | ||
| clients.forEach((s) => { | ||
| if (socket.name !== s.name) | ||
| s.write(socket.name + ': ' + chunk.toString()); | ||
| }); | ||
| }); | ||
| }).listen(3000, () => { | ||
| console.log('Up on 3000'); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| const net = require('net'); | ||
| const expect = require('chai').expect; | ||
| const server = require('../tcp_server'); | ||
|
|
||
| describe('tcp tests', () => { | ||
| it('should send message to all clients, but not to sender', (done) => { | ||
| var result; | ||
| var wroteBack = false; | ||
| var firstClient = net.connect(3000, () => { | ||
| firstClient.on('data', (data) => { | ||
| if (data.toString() !== 'Sending message\n') wroteBack = true; | ||
| }) | ||
| firstClient.write('message'); | ||
| }) | ||
| var secondClient = net.connect(3000, () => { | ||
| secondClient.on('data', (data) => { | ||
| result = data.toString(); | ||
| }) | ||
| }); | ||
| setTimeout(() => { | ||
| expect(result.slice(-7)).to.eql('message'); | ||
| expect(wroteBack).to.eql(false); | ||
| done(); | ||
| }, 200) | ||
| }) | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you add your own property to an instance you could run into a problem if the instance already has a property using that name. You could check docs, use a test in code (!socket.name) to be sure its not used, or assign a more app specific name like myapp_name. In this code you probably don't need to save it because you're using the value of a property that already exists. Wherever you're test or outputting socket.name, you could just use socket.remotePort. If you wanted to maintain a really app specific name, your sockets array could contain an array of objects, each of which holding the socket and the unique name like sockets = [{socket: , name:"Fred"}];. That all said, your stretch to supply a user id works!