Router と WebSocket

  • 2,377 views
Uploaded on

第2回CloudFoundry輪読会講演資料 …

第2回CloudFoundry輪読会講演資料

cloud foundryのrouterとかを弄って、WebSocket動くようにしてみましたよ!!というお話

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,377
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
32
Comments
0
Likes
3

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
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Transcript

  • 1. Router WebSocket 2011/11/17(thu) 2 CloudFoundry
  • 2. • (@komasshu)• WebSocket• Google API Expert (HTML5)• Microsoft Valuable Professional (IE)
  • 3. CloudFoundryWebSocket ...
  • 4. WebSocket• HTML5 API/Protocol• Web •
  • 5. • Web(port=80) VPN • SSL-VPN
  • 6. Handshake
  • 7. Handshake
  • 8. HandshakeFrames
  • 9. point : UpgradeRequest Header (client => server) GET /chat HTTP/1.1 Host: server.example.com Upgrade: websocketResponse Header (server => client) HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Upgrade HTTP WebSocket
  • 10. HTTP Compatible• VPN • FW, Proxy • HTTP/1.1 • • Web VPN
  • 11. http://www.ericom.com/html5_client_vmware_view.asp http://www.publickey1.jp/blog/11/webhtml5.html
  • 12. CloudFoundry WebSocket orz• why? • nginx 2 • router HTTP/1.1 rails sinatra nginx router node.js DEA
  • 13. • nginx • zip Access log HTTPS• router • URL routing URL routing unix domain tcp socket socket rails (tcp socket ) 80/443 sinatra nginx router node.js DEA
  • 14. WebSocket nginx • Request HTTP (502) • tcp_proxy Patch •https://github.com/yaoweibin/nginx_tcp_proxy_module
  • 15. nginx.conftcp { upstream vcap_router { server unix:/tmp/router.sock;# server 127.0.0.1:2222;# check interval=3000 rise=2 fall=5 timeout=1000; } tcp_nodelay off; server { listen 80; server_name _; proxy_read_timeout 200000; proxy_send_timeout 200000; proxy_pass vcap_router; }}
  • 16. WebSocket router• HTTP Request/Response HTTP• WebSocket Frames• HTTP
  • 17. dialog of router.rb request Header router request/sec Router on_headers _complete() unix module module node.jsnginx domain TCP socket socket ClientConnection AppConnection on_headers _complete() response Header response latency
  • 18. WebSocketUpgrade: websocket proof of conceptWebsocketConnection router module TCP socket node.js on_headers AppConnection _complete() on_headers unix module _complete() nginx domain socket ClientConnection module WebsocketConne TCP socket node.js ction WS
  • 19. client_connection.rbdef on_headers_complete(headers) .... # [kom] Check connection mode(websocket or not) @is_websocket = (headers[UPGRADE_HEADER] == WEBSOCKET) ? true : false Router.log.info "@is_websocket : #{@is_websocket}" .... if (@is_websocket) host, port = @droplet[:host], @droplet[:port] @bound_app_conn = EM.connect(host, port, WebsocketConnection, self,@headers, @droplet) return end ....end
  • 20. websocket_connection.rbmodule WebsocketConnection def initialize client, header, droplet @client, @header, @droplet = client, header, droplet end def connection_completed send_data(@header) end def receive_data(data) @client.send_data(data) end def terminate end orzend
  • 21. Demo (echo server)
  • 22. • proof of concept• production• zip, ssl NG• WebSocketConnection• :)
  • 23. Thank you!!http://twitter.com/komasshu