nodejs introduce - using socket.io

49
@clonn (Caesar Chi) ttp://nodejs.org/ clonn.blogspot.com

Upload: caesar-chi

Post on 20-Aug-2015

2.439 views

Category:

Technology


13 download

TRANSCRIPT

Page 1: Nodejs introduce - using Socket.io

@clonn (Caesar Chi)http://nodejs.org/ clonn.blogspot.com

Page 2: Nodejs introduce - using Socket.io

學習任何事物都必須

Page 3: Nodejs introduce - using Socket.io

快快樂樂

Page 4: Nodejs introduce - using Socket.io

因此本次主題訂為

Page 5: Nodejs introduce - using Socket.io

快快樂樂學習

Page 6: Nodejs introduce - using Socket.io

為何使用 nodeJS?

Page 7: Nodejs introduce - using Socket.io

為了實現即時回應Facebook, plurk 的即時回饋,讓我回不去了…

Page 8: Nodejs introduce - using Socket.io

activeMQ, erlang, Twisted, jetty comet, php comet…

找了許多套實現方式

Page 9: Nodejs introduce - using Socket.io

從中選擇了

Page 10: Nodejs introduce - using Socket.io

Apache(nginx) + PHP

V8 Engine Javascript

Page 11: Nodejs introduce - using Socket.io

優勢???

Page 12: Nodejs introduce - using Socket.io

非阻塞 non-blocking

每個程序當中,皆能平均分享資源,確保程序執行資源不會被鎖死

Page 13: Nodejs introduce - using Socket.io

事件驅動 event-driven

經由事件觸發才會開始執行流程,一般都會處於等待狀態

Page 14: Nodejs introduce - using Socket.io

CommonJS

一種標準,提供javascript 標準設計規範於各個平台

Page 15: Nodejs introduce - using Socket.io

NPM

Node 模組管理,方便於管理模組套件。

Page 16: Nodejs introduce - using Socket.io

任何平台適用

Linux , Mac ,以及windows 都可以正常運作。(v 0.5.0 之後 )

Page 17: Nodejs introduce - using Socket.io

Javascript

採用 javascript ,利用v8 編譯腳本,執行程序並不限定於瀏覽器中。

前端工程師基本配備 =b

Page 18: Nodejs introduce - using Socket.io

nodeJS 學習方式?

Page 19: Nodejs introduce - using Socket.io

快快樂樂閱讀 API

Page 20: Nodejs introduce - using Socket.io

STDIO (console)Timer

Page 21: Nodejs introduce - using Socket.io

Timerprocess

Page 22: Nodejs introduce - using Socket.io

processHTTP

Page 23: Nodejs introduce - using Socket.io

HTTPQueryString

Page 24: Nodejs introduce - using Socket.io

QueryStringFile system

Page 25: Nodejs introduce - using Socket.io

這些 API…有個印象就好

Page 26: Nodejs introduce - using Socket.io

安裝 nodejssudo apt-get install nodedownload node.exe (windows)

Page 27: Nodejs introduce - using Socket.io

安裝 npmcurl http://npmjs.org/install.sh |

sh

Page 28: Nodejs introduce - using Socket.io

console.log(“hello world”);

node ↓

快快樂樂測試 node

(/"≡ _ ≡)/~┴┴

Page 29: Nodejs introduce - using Socket.io

學習 nodejs的初衷產生即時服務 (real time)

Page 30: Nodejs introduce - using Socket.io

nodeJS simple code

Page 31: Nodejs introduce - using Socket.io

nodeJS

Page 32: Nodejs introduce - using Socket.io

Fro

nt e

nd

javascrip

t cod

e

那麼長…看行數都想睡覺

Page 33: Nodejs introduce - using Socket.io

用原生的 nodeJS一堆坑 …而且不快樂

還記得今天的標題?

Page 34: Nodejs introduce - using Socket.io

快快樂樂學習

Page 35: Nodejs introduce - using Socket.io

http://www.oreillymaker.com/

Page 36: Nodejs introduce - using Socket.io

socket.io

跨瀏覽器,整合前後端,即時回饋實現方案。

Page 37: Nodejs introduce - using Socket.io

瀏覽器支援

WebSocketFlash® SocketAJAX long pollingAJAX multipartForever IframeJSONP Polling

Page 38: Nodejs introduce - using Socket.io

安裝 Socket.ionpm install socket.io

Page 39: Nodejs introduce - using Socket.io

模組引用

http, file read

Port listenSocket.io watch

Socket.io event

Page 40: Nodejs introduce - using Socket.io

前端套件引用Socket.io watch

Socket.io event

Page 41: Nodejs introduce - using Socket.io

Server Code

Client Code

Page 42: Nodejs introduce - using Socket.io

Code 變簡單專注於開發就對了

Page 43: Nodejs introduce - using Socket.io

結語

Page 44: Nodejs introduce - using Socket.io

單一切入 nodeJS

找尋太多外掛會迷失方向nodeJS + ? = ∞

Page 45: Nodejs introduce - using Socket.io

nodeJS 資源?

Page 46: Nodejs introduce - using Socket.io

The Node Beginner BookMastering Node.jsUp and Running with Node.js

nodejs.orggithub.com/joyent/node/wiki/Community

Page 47: Nodejs introduce - using Socket.io

wiki.nodejs.tw

Page 48: Nodejs introduce - using Socket.io

Q & A ?

Page 49: Nodejs introduce - using Socket.io

謝謝!