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

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

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

Ca0ab6e450f894e06652ee257df9d647?s=128

Shuhei Kagawa

June 07, 2013
Tweet

Transcript

  1. 2.

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

    ͰαΠωʔδɺ Ruby on Rails Ͱ ΋Ζ΋ΖɺͳͲ! ޷͖ͳݴޠ͸ Ruby ͱ JavaScript ͱ࠷ۙ Scala
  2. 4.

    Server! Client! Browser! HTTP Proxy Mobile! Safari Websit Adhoc Network

    Web! Socket Web! Socket Websit Websit Architecture
  3. 10.

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

    http://d.hatena.ne.jp/Jxck/20120725/ 1343174392 http://www.flickr.com/photos/60317050@N08/8735098936/
  4. 12.

    WebSocket Protocol 0: FIN+OPCODE, 1: Payload Length, 2-: Payload! 0:

    FIN+OPCODE, 1: 0x7e, 2-3: Payload Length, 4-: Payload! ҎԼಉจ! socket ͷσʔλΛ஍ಓʹ 1byte ͣͭຒΊΔ/ಡ ΈऔΔ
  5. 13.

    Server! Client! Browser! HTTP Proxy Mobile! Safari Websit Adhoc Network

    Web! Socket Web! Socket Websit Websit Architecture
  6. 14.

    TCP server as HTTP Proxy Browser ͔Βͷ request Λ TCP

    server Ͱड͚ Δ! Binary ͷ·· WebSocket Ͱ server ΁! σʔλͷઌ಄ʹ 2 byte ෼ port ൪߸Λ෇Ճ
  7. 15.

    TCP client as HTTP client WebSocket ͰૹΒΕ͖ͯͨ binary Λɺ࠷ॳͩ ͚

    toString ͯ͠ host:port Λऔಘ! TCP ઀ଓͨ͠Βɺޙ͸ͻͨ͢Β binary Λྲྀ͢
  8. 17.

    HTTP server & client ʹ ΍ͬͺΓϦΫΤετຖʹ header Λ parse ͠

    ͳ͍ͱବ໨ͩͬͨ! HTTP request Λ parse ͢ΔͳΒ http.Server! Node ͷ HTTP parser ͸ native
  9. 18.

    ࠞઢΛ๷͙ Browser ͔Βͷ request ຖʹ 16 byte ͷ UUID ΛৼΔ!

    Server ଆͰ΋ɺUUID Λ΋ͱʹࣝผ! ෳ਺୺຤ରԠͯ͠΋ࠞઢ͠ͳ͍͸ͣ
  10. 19.

    HTTPS CONNECT request! Socket ͔Βͷ data Λ browser ͔Β web

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