Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Node.js + WebSocket でテザリングしてみた

Node.js + WebSocket でテザリングしてみた

社内勉強会での発表です。
https://github.com/shuhei/tether

Shuhei Kagawa

June 07, 2013
Tweet

More Decks by Shuhei Kagawa

Other Decks in Programming

Transcript

  1. ࣗݾ঺հ 5/1 ೖࣾ! લ৬Ͱ͸ .NET Ͱ CAD ΧελϚΠζɺ Web ੍࡞ɺFlash

    ͰαΠωʔδɺ Ruby on Rails Ͱ ΋Ζ΋ΖɺͳͲ! ޷͖ͳݴޠ͸ Ruby ͱ JavaScript ͱ࠷ۙ Scala
  2. Server! Client! Browser! HTTP Proxy Mobile! Safari Websit Adhoc Network

    Web! Socket Web! Socket Websit Websit Architecture
  3. ࣗ࡞ • ࡞ͬͯΈΑ͏ʂ • ࢓༷ॻ http://tools.ietf.org/html/rfc6455 • WebSocket αʔόͷ࣮૷ͱϓϩτίϧ ղઆ

    http://d.hatena.ne.jp/Jxck/20120725/ 1343174392 http://www.flickr.com/photos/60317050@N08/8735098936/
  4. WebSocket Protocol 0: FIN+OPCODE, 1: Payload Length, 2-: Payload! 0:

    FIN+OPCODE, 1: 0x7e, 2-3: Payload Length, 4-: Payload! ҎԼಉจ! socket ͷσʔλΛ஍ಓʹ 1byte ͣͭຒΊΔ/ಡ ΈऔΔ
  5. Server! Client! Browser! HTTP Proxy Mobile! Safari Websit Adhoc Network

    Web! Socket Web! Socket Websit Websit Architecture
  6. TCP server as HTTP Proxy Browser ͔Βͷ request Λ TCP

    server Ͱड͚ Δ! Binary ͷ·· WebSocket Ͱ server ΁! σʔλͷઌ಄ʹ 2 byte ෼ port ൪߸Λ෇Ճ
  7. TCP client as HTTP client WebSocket ͰૹΒΕ͖ͯͨ binary Λɺ࠷ॳͩ ͚

    toString ͯ͠ host:port Λऔಘ! TCP ઀ଓͨ͠Βɺޙ͸ͻͨ͢Β binary Λྲྀ͢
  8. HTTP server & client ʹ ΍ͬͺΓϦΫΤετຖʹ header Λ parse ͠

    ͳ͍ͱବ໨ͩͬͨ! HTTP request Λ parse ͢ΔͳΒ http.Server! Node ͷ HTTP parser ͸ native
  9. ࠞઢΛ๷͙ Browser ͔Βͷ request ຖʹ 16 byte ͷ UUID ΛৼΔ!

    Server ଆͰ΋ɺUUID Λ΋ͱʹࣝผ! ෳ਺୺຤ରԠͯ͠΋ࠞઢ͠ͳ͍͸ͣ
  10. HTTPS CONNECT request! Socket ͔Βͷ data Λ browser ͔Β web

    server ΁ૉ௨͢͠Δ! ૉ௨͠ͳͷͰɺ҉߸Խ͞Ε͍ͯͯ΋໰୊ͳ͠