Created
May 28, 2014 14:45
-
-
Save rizowski/15f522fc34b88370118c to your computer and use it in GitHub Desktop.
[TW] Node.js Examples (v0.10.28)
This file contains 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
var http = require('http'); | |
http.createServer(function(request, response) { | |
response.writeHead(200, {'content-Type' : 'text/plain'}); | |
response.end("helloWorld"); | |
}).listen(8080, '127.0.0.1'); | |
console.log("Running Server on http://127.0.0.1:8080"); |
This file contains 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
var net = require('net'), | |
readline = require('readline'); | |
var client = new net.Socket(); | |
client.connect(8081, '127.0.0.1', function() { | |
console.log('Connected'); | |
var rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
rl.on('line', function(cmd){ | |
console.log("Sending: "+ cmd); | |
client.write(cmd); | |
}); | |
}); | |
client.on('data', function(data) { | |
console.log('Received: ' + data); | |
}); | |
client.on('close', function() { | |
console.log('Connection closed'); | |
}); |
This file contains 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
var net = require('net'), | |
readline = require('readline'); | |
var server = net.createServer(); | |
server.on('connection', function(socket){ | |
console.log("Connected! " + socket.remoteAddress); | |
socket.write("Welcome " + socket.remoteAddress); | |
socket.on('data', function(message){ | |
console.log('Recieved "' + message + '". Applying mistifications.'); | |
message = message + "!"; | |
socket.write(message); | |
}); | |
}); | |
server.listen(8081, '127.0.0.1'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment