Created
October 19, 2013 11:32
-
-
Save nasser-torabzade/7054775 to your computer and use it in GitHub Desktop.
the app starts with `nodeIndex.js`
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 httpPort = 80; | |
var http = require('http'); | |
function start(){ | |
http.createServer(onRequest).listen(httpPort); | |
function onRequest (request, response) { | |
request.setEncoding("utf8"); | |
var postData = ""; | |
request.addListener("data", function(postDataChunk) { | |
postData += postDataChunk; | |
}); | |
request.addListener("end", function() { | |
// serving files if performed here | |
}); | |
} | |
} | |
exports.start = start; |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<script src="socket.io.js"></script> | |
<script> | |
document.cookie="foo=bar"; | |
var socket = io.connect('http://localhost:3000'); | |
</script> | |
</head> | |
<body> | |
hello world! | |
</body> | |
</html> |
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 httpServer = require("./httpServer.js"); | |
var socketServer= require("./socketServer.js"); | |
httpServer.start(); | |
socketServer.start(); |
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 socketPort = 3000; | |
var io = require('socket.io').listen(socketPort, { log: false }); | |
function start() { | |
io.sockets.on('connection', function (socket) { | |
// no cookies is here! | |
console.log(socket.handshake.headers); | |
}); | |
} | |
exports.start = start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment