Handwritten Text Recognition for manuscripts and early printed texts
Node.js and websockets intro
1. Node.js and
WebSockets
A (very) short introduction
Andreas Kompanez
Montag, 26. April 2010
2. Node.js
JavaScript Framework
Server-side
Uses V8
Evented and non-blocking
CommonJS
Uses ECMAScript 5
Montag, 26. April 2010
3. Node.js
Created by Ryan Dahl
~8000 lines of C/C++ and 2000 lines
JavaScript
http://nodejs.org/
Montag, 26. April 2010
4. Evented?
Old (blocking) school:
<?php
$content = file_get_contents("/some/huge/file");
doThings($content); // Waiting, synchron
otherThing();
Montag, 26. April 2010
5. Evented?
Evented I/O
file.read("/some/huge/file", function(data) {
// called after data is read
doThings(data);
});
otherThing(); // execute immediately;
Montag, 26. April 2010
6. Benefits
Asynchronous programming
Event-loops instead of threads
Non-blocking
1 Thread (No context switching etc.)
Montag, 26. April 2010
8. CommonJS
A collection/library of standards
Modules
Binary
File system
and many more!
Montag, 26. April 2010
9. CommonJS Modules
There should be a function require
There should be a var called exports
Montag, 26. April 2010
10. Module Example
// math.js module
exports.multiply = function(a, b) {
return a * b;
}
// Some other file, using math.js
//
var math = require('./math');
var sys = require('sys');
sys.puts(math.multiply(12, 12));
Montag, 26. April 2010
11. Google V8 JavaScript
Engine
It’s a VM!
Developed by Google
The team lead is Lars Bak (Sun’s Java
VM & Smalltalk VM)
No JIT, compiled to Assembler
Montag, 26. April 2010
12. The 6+ lines http
server
// httpserver.js
// Usage: node httpserver.js
var sys = require("sys"),
http = require("http");
http.createServer(function(request, response) {
var headers = { "Content-Type": "text/plain" };
response.sendHeader(200, headers);
response.write("Hello, World!n");
response.close();
}).listen(8000);
sys.puts("Running at http://127.0.0.1:8000/");
Montag, 26. April 2010