Permalink
Browse files

Initial Loadup of my node exercises

  • Loading branch information...
0 parents commit 4e706b32a70ad1e0c15d81ec869d954fec1c5096 Gunnar Magholder committed Jul 11, 2013
Showing with 61 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. BIN .silkveil.js.swp
  3. +19 −0 chat.js
  4. +12 −0 http_server.js
  5. +4 −0 hw.js
  6. +24 −0 silkveil.js
@@ -0,0 +1,2 @@
+*~
+.*
Binary file not shown.
19 chat.js
@@ -0,0 +1,19 @@
+var net = require('net');
+var sockets = [];
+
+net.createServer(function (socket) {
+ sockets.push(socket);
+ socket.write('Hallo!\n');
+ socket.on('data', function(data) {
+ for(var i = 0; i< sockets.length; i++) {
+ if(sockets[i] == socket) {
+ continue;
+ };
+ sockets[i].write(data);
+ }
+ });
+ socket.on('end', function() {
+ var i = sockets.indexOf(socket);
+ sockets.splice(i,1);
+ });
+}).listen(3000);
@@ -0,0 +1,12 @@
+var http = require('http');
+
+var server = http.createServer(function(req,res) {
+ console.log('Initializing Server...');
+ res.writeHead(200, {
+ 'content-type': 'text/plain'
+ });
+ res.write('Hallo ');
+ setTimeout(function(){
+ res.end('Welt!');
+ },2000);
+}).listen(3000);
4 hw.js
@@ -0,0 +1,4 @@
+setTimeout(function() {
+ console.log('Welt!');
+}, 2000);
+console.log("Hallo ");
@@ -0,0 +1,24 @@
+var http = require('http');
+var mappings = {
+ 'magholder': {
+ action: 'redirect',
+ url: 'http://magholder.info',
+ type: 'permanent'
+ },
+ 'ursel': {
+ action: 'download',
+ url: 'https://www.facebook.com/photo.php?fbid=10201281285979248&l=76a440aac7',
+ fileName: 'ursel.jpg',
+ forceDownload: false
+ }
+};
+http.createServer(function(req,res) {
+ var alias = req.url.substring(1);
+ var mapping = mappings[alias] || {
+ action: 'error',
+ statusCode: 404,
+ data: 'file not found'
+ };
+ actions[mapping.action](res.mapping);
+ console.log(mapping);
+}).listen(3000);

0 comments on commit 4e706b3

Please sign in to comment.