• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
NodeJS快速服务端开发 朝沐金风 Shanghai
 

NodeJS快速服务端开发 朝沐金风 Shanghai

on

  • 1,659 views

 

Statistics

Views

Total Views
1,659
Views on SlideShare
1,659
Embed Views
0

Actions

Likes
1
Downloads
17
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • QQ 79194034 Email : [email_address] 微博: weibo.com/bombworm
  • http:// oddments.org/?p =494

NodeJS快速服务端开发 朝沐金风 Shanghai NodeJS快速服务端开发 朝沐金风 Shanghai Presentation Transcript

  • Node JS 快速服务端开发 赵磊 2011-06-18
  • 为什么要使用 NodeJS
  • NodeJS 不是服务器
    • 它是让你可以让我们自定义网络服务器 / 客户端的一个工具
  • 监听未捕获错误
    • process.on( 'uncaughtException' , function (err) {
    • // 记录错误,不过对这个方法不要太乐观
    • console.dir(err);
    • });
  • 创建简单 TCP 服务器
    • var net = require( 'net' );
    • var server = net.createServer( function (socket) {
    • socket.write( 'Hello NodeJSrn' ); socket.pipe(socket);
    • });
    • server.listen( 1127 );
  • 创建简易 HTTP 服务器
    • var http = require( 'http' );
    • var server = http.createServer( function (req, res){
    • res.writeHead( 200 , { 'Content-Type' : 'text/plain' }); res.end( 'Hello NodeJSrn' );
    • });
    • server.listen( 1127 );
  • 创建跨浏览器实时连接服务
    • git://github.com/LearnBoost/Socket.IO.git
    • git://github.com/LearnBoost/Socket.IO-node.git
    • WebSocket
    • Adobe® Flash® Socket
    • AJAX long polling
    • AJAX multipart streaming
    • Forever Iframe
    • JSONP Polling
  • WebSocket 握手协议
    • 1 取 Sec-WebSocket-Key1 中数字组成字符串 s1
    • 2 取 Sec-WebSocket-Key1 中空格数 n1
    • 3 s1/n1 取整得到 k1
    • 4 k1 每 2 字节作为 ascii 码转换成字符逆序组成 p1
    • 5 Sec-WebSocket-Key2 重复 1-4 步取得 p2
    • 6 从实体正文中取得最后 8 字节 p3
    • 7 MD5(p1+p2+p3) 得到 16 字节的 binary
    WebSocket 握手协议
    • Python 算法描述:
    • import struct, md5 ... spaces1 = key1.count(" ") spaces2 = key2.count(" ") num1 = int("".join([c for c in key1 if c.isdigit()])) / spaces1 num2 = int("".join([c for c in key2 if c.isdigit()])) / spaces2 return md5(struct.pack('>II8s', num1, num2, key3)).digest()
    WebSocket 握手协议
  • WebSocket 握手协议
  • Q&A