Skip to content

Instantly share code, notes, and snippets.

@nasser-torabzade
Created October 19, 2013 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nasser-torabzade/7054775 to your computer and use it in GitHub Desktop.
Save nasser-torabzade/7054775 to your computer and use it in GitHub Desktop.
the app starts with `nodeIndex.js`
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;
<!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>
var httpServer = require("./httpServer.js");
var socketServer= require("./socketServer.js");
httpServer.start();
socketServer.start();
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