Devcamp - by Node - Js 2010
Devcamp - by Node - Js 2010
js
Возможности и перспективы
Antono Vasiljev
http://antono.info/
http://github.com/antono/
http://groups.google.com/group/ru-nodejs/
Краткая история всего
http://nodejs.org/
System Threads vs Single Thread
Apache
Node.js
Событийная, асинхронная модель
обработки данных
Операции ввода-вывода
унифицированы реализуют
интерфейс Stream
Объекты выполняющие I/O регистрируют
обработчики событий
И вызывают их...
$.get('ajax/test.html', function(data) {
$('.result').html(data);
alert('Load was performed.');
});
$.ajax({
url: 'ajax/test.html',
success: function(data) {
$('.result').html(data);
alert('Load was performed.');
},
error: function() {},
complete: function() {},
beforeSend: function() {}
});
var http = require('http');
var google = http.createClient(80, 'www.google.com');
// socket.io
var socket = io.listen(server);
socket.on('connection', function(client){
// new client is here!
client.on('message', function(){ … })
client.on('disconnect', function(){ … })
});
var socket = new io.Socket();
socket.on('connect', function(){
socket.send('hi!');
})
socket.on('message', function(data){
alert(data);
})
socket.on('disconnect', function(){})
Nordstream
var connections = 0;
var nodestream = io.listen(app).nodestream()
.on('connect', function(){
connections++;
this.emit('connections', connections);
})
.on('disconnect', function(){
connections--;
this.emit('connections', connections);
});