Your SlideShare is downloading. ×
0
WebSocket 实时推特流
WebSocket 实时推特流
WebSocket 实时推特流
WebSocket 实时推特流
WebSocket 实时推特流
WebSocket 实时推特流
WebSocket 实时推特流
WebSocket 实时推特流
WebSocket 实时推特流
WebSocket 实时推特流
WebSocket 实时推特流
WebSocket 实时推特流
WebSocket 实时推特流
WebSocket 实时推特流
WebSocket 实时推特流
WebSocket 实时推特流
WebSocket 实时推特流
WebSocket 实时推特流
WebSocket 实时推特流
WebSocket 实时推特流
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

WebSocket 实时推特流

2,090

Published on

Example Code: …

Example Code:
http://github.com/shaokun/twlive

1 Comment
1 Like
Statistics
Notes
  • the example code is here:
    http://github.com/shaokun/twlive
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
2,090
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
45
Comments
1
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. WebSocket 实时推特流 [email_address]
  • 2. 需要了解的概念
    • HTML 5 WebSocket
    • EventMachine (EM)
    • HTTP Stream
  • 3. Browser HTML 5 WebSocket EM::WebSocket EM::Channel EM::HttpRequest Twitter Stream Browser HTML 5 WebSocket Browser HTML 5 WebSocket EM::WebSocket EM::WebSocket Publish Subscribe TCP Channel
  • 4. HTML 5 WebSocket
  • 5.
    • 通过 Web 的 Socket
    • 全双工的通讯通道
    • 双向通讯
    • 更小的延迟,实时的
  • 6.
    • < script type = &quot;text/javascript&quot; >
    • // 创建 WebSocket 对象很容易
    • ws = new WebSocket ( &quot;ws://localhost:8080/&quot; );
    • </ script >
  • 7.  
  • 8. ws . onopen = function () {...}; ws . onclose = function () {...}; ws . onerror = function (event) {...}; ws . onmessage = function (event) {...};
  • 9. ws . send (msg); ws . close ();
  • 10. 支持的 Browsers
    • Chrome
    • Safari 4.x
    • Firefox 3.7
    • IE ??? github.com/gimite/web-socket-js
  • 11. EventMachine simple, fast, event-driven I/O library for Ruby
  • 12. EM::WebSocket
  • 13.
    • EM :: WebSocket .start( :host => &quot;localhost&quot; , :port => 8080) do | ws |
    • ws.onopen do
    • end
    • ws.onclose do
    • end
    • end
  • 14. Publish/Subscribe EM::Channel
  • 15.
    • channel = EM :: Channel . new
    • channel << &quot;a new message&quot;
    • sid = channel.subscribe do | msg |
    • puts msg # should output ‘a new message’
    • end
  • 16. HTTP Stream
  • 17. Twitter Stream API
    • http://stream.twitter.com/1/statuses/sample.json
    • http://stream.twitter.com/1/statuses/filter.json?track=???
  • 18.
    • url = 'http://stream.twitter.com/1/statuses/sample.json'
    • buffer = &quot;&quot;
    • http.stream do | chunk |
    • buffer += chunk
    • while line = buffer.slice!(/.+ ? /)
    • tweet = JSON .parse(line)
    • next unless tweet[ 'text' ]
    • msg = &quot;#{tweet['user']['screen_name']}: #{tweet['text']}&quot;
    • channel << msg
    • end
    • end
  • 19. Browser HTML 5 WebSocket EM::WebSocket EM::Channel EM::HttpRequest Twitter Stream Browser HTML 5 WebSocket Browser HTML 5 WebSocket EM::WebSocket EM::WebSocket Publish Subscribe TCP Channel
  • 20. 问答 ??? QA [email_address]

×