diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/.DS_Store differ diff --git a/robin_stringer/.DS_Store b/robin_stringer/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/robin_stringer/.DS_Store differ diff --git a/README.md b/robin_stringer/README.md similarity index 100% rename from README.md rename to robin_stringer/README.md diff --git a/robin_stringer/package.json b/robin_stringer/package.json new file mode 100644 index 0000000..005d5ce --- /dev/null +++ b/robin_stringer/package.json @@ -0,0 +1,27 @@ +{ + "name": "robin_stringer", + "version": "1.0.0", + "description": "Create a TCP Server ======================== To complete this assignment: * fork this repository (the sub module for this specific assignment) * clone down your fork * place all of your work in a folder that is your full name, use `_`s instead of spaces * push back up to your fork * create a pull request back to the original repo * submit a link to the PR in canvas", + "main": "gulpfile.js", + "directories": { + "test": "test" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node server.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/rastringer/create_a_tcp_server.git" + }, + "author": "ra1stringer@gmail.com", + "license": "MIT", + "bugs": { + "url": "https://github.com/rastringer/create_a_tcp_server/issues" + }, + "homepage": "https://github.com/rastringer/create_a_tcp_server#readme", + "devDependencies": { + "chai": "^3.4.1", + "mocha": "^2.3.3" + } +} diff --git a/robin_stringer/server.js b/robin_stringer/server.js new file mode 100644 index 0000000..47ac951 --- /dev/null +++ b/robin_stringer/server.js @@ -0,0 +1,28 @@ +// Write a simple tcp logging server. This server should receive tcp requests and save the request into a file. +'use strict'; +var fs = require('fs'); +var net = require('net'); +var port = 3000; + +var server = net.createServer(function(socket) { + socket.on('data', function(data) { + console.log(data.toString()); + +fs.writeFile((Date.now().toString()), data, function(err) { + if(err) throw err; + console.log('Saved!'); + }); +}); + + socket.on('end', function() { + console.log('socket closed'); + }); + + server.close(function() { + console.log('Server closed'); + }); +}); + +server.listen('3000', function() { + console.log('server up on port ' + port); +}); diff --git a/robin_stringer/test/test.js b/robin_stringer/test/test.js new file mode 100644 index 0000000..ed1cbef --- /dev/null +++ b/robin_stringer/test/test.js @@ -0,0 +1,10 @@ +'use strict'; + +var chai = require('chai'); +var net = require('net'); +var fs = require('fs'); + +describe('tcp server responding', function() { + it('should have status 200', function() { + }); +});