"Socket.IO aims to make realtime apps possible in every browser and mobile device, blurring the differences between the different transport mechanisms. It's care-free realtime 100% in JavaScript."— http://socket.io
Sometimes called "the jQuery for realtime applications."
Two components:
socket.io-client
: runs in the
browser
socket.io
: runs on the server;
serves the static JS
socket.io-client
files
// Client source file
var defaultOptions = {
// These values are expanded at build time.
host: "",
port: ""
};
// Build script (Grunt)
NODE_HOST: process.env.NODE_HOST || "127.0.0.1",
NODE_PORT: process.env.NODE_PORT || 8000,
// Inject NODE_HOST and NODE_PORT values into files as they are
// copied
processContent: function(content) {
return content.replace(/\{\{\s*(NODE_HOST|NODE_PORT)\s*\}\}/g,
function(match, varName) {
return grunt.config("meta." + varName);
}
);
}
fs.*Sync()
Generally a bad practice--it blocks the execution thread.
Acceptable during application initialization.
// One approach
socketServer.sockets.on("connection", function(socket) {
if (app.isLive()) {
connectLive.apply(socket, arguments);
} else {
offlineConnection.apply(socket, arguments);
}
});
// Another approach
socketServer.sockets.on("connect", function(socket) {
socketHandlers.connection.apply(socket, arguments);
});
// elsewhere...
socketHandlers.connection = connectLive;
dev
user with sudo
rightsnode
user with limited rightsInstall to /opt/joyent/node/
(check out the Filesystem Hierarchy Standard for some light reading)
$ sudo chown users:dev /opt/joyent/node
apt-get install htop
apt-get install sysstat
I wanted to simulate long-polling connections from Node.js (see how). Socket.io required a patch to support this.
"Amazon Web Services offers a complete set of infrastructure and application services that enable you to run virtually everything in the cloud: from enterprise applications and big data projects to social games and mobile apps."
Lucky for us, there's a Free usage tier.
* Amazon refused to pay me for this slideA utility for arming (creating) many bees (micro EC2 instances) to attack (load test) targets (web applications).— Bees with Machine Guns project page
"But... why?!"
We need a slightly more generalized approach to run our Node.js client simulator.
Use a spacebar or arrow keys to navigate