Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Node.js + WebSocket でテザリングしてみた
Search
Shuhei Kagawa
June 07, 2013
Programming
0
2.6k
Node.js + WebSocket でテザリングしてみた
社内勉強会での発表です。
https://github.com/shuhei/tether
Shuhei Kagawa
June 07, 2013
Tweet
Share
More Decks by Shuhei Kagawa
See All by Shuhei Kagawa
Profiling Node.js apps on production
shuhei
0
820
Building a Pixel Art Editor with Elm
shuhei
1
740
Redux Middleware Wars (Japanese)
shuhei
8
1.8k
Redux Middleware Wars (English)
shuhei
0
150
Draw Animated Chart on React Native
shuhei
0
8.7k
Angular 2 Offline Compiler
shuhei
0
5.4k
Weird Attractors
shuhei
0
820
Angular 2 @ JS Ojisan #6-3
shuhei
1
3k
Introduction to Angular 2
shuhei
2
140
Other Decks in Programming
See All in Programming
Jakarta EE meets AI
ivargrimstad
0
530
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
2
660
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.2k
CSC509 Lecture 11
javiergs
PRO
0
180
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
subpath importsで始めるモック生活
10tera
0
300
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
役立つログに取り組もう
irof
28
9.6k
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
イベント駆動で成長して委員会
happymana
1
320
EventSourcingの理想と現実
wenas
6
2.3k
距離関数を極める! / SESSIONS 2024
gam0022
0
280
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
32
1.5k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
Writing Fast Ruby
sferik
627
61k
A designer walks into a library…
pauljervisheath
203
24k
Typedesign – Prime Four
hannesfritz
40
2.4k
Making Projects Easy
brettharned
115
5.9k
Visualization
eitanlees
145
15k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
How GitHub (no longer) Works
holman
310
140k
Bash Introduction
62gerente
608
210k
Rails Girls Zürich Keynote
gr2m
94
13k
Transcript
Node.js + WebSocket Ͱ ςβϦϯάͯ͠Έͨ 2013/6/7 M3 Tech Talk #2!
! ߳ पฏ
ࣗݾհ 5/1 ೖࣾ! લ৬Ͱ .NET Ͱ CAD ΧελϚΠζɺ Web ੍࡞ɺFlash
ͰαΠωʔδɺ Ruby on Rails Ͱ ΖΖɺͳͲ! ͖ͳݴޠ Ruby ͱ JavaScript ͱ࠷ۙ Scala
https://github.com/shuhei/tether
Server! Client! Browser! HTTP Proxy Mobile! Safari Websit Adhoc Network
Web! Socket Web! Socket Websit Websit Architecture
ंྠͷ࠶ൃ໊ • t.free http://connectfree.jp/tetherfree/! • https://github.com/spoletto/iOS-HTML5- Tethering! • େֶͷ՝ http://cs.brown.edu/courses/cs168/s12/
handouts/tether.pdf http://www.flickr.com/photos/60317050@N08/8595670162
ಈػ 12/15 ιϑτόϯΫͷςβϦϯάղېΑΓલ! ͜Ε·Ͱ্ͬ໘͔Γɾɾɾ͏ͪΐͬͱԼ ͷํΛͪΌΜͱΓ͍ͨ! Node.js Ͱ Express, Socket.IO Θͳ͍ͷ
࡞Γ͍ͨ
TUN TAP Software network device! ͷύέοτશͯΛԣऔΓͰ͖Δ! ͰɺNode.js Ͱ৮Εͳͦ͞͏ɾɾɾ! Native module
ॻ͚ͳ͍͠ɾɾɾ
HTTP Proxy TCP Ҏ্ͳΒ Node.js Ͱ؆୯ʹ৮ΕΔ! HTTP Tunneling ͢Εɺ͍Ζ͍Ζͳϓϩτί ϧαϙʔτͰ͖Δͣʂ
WebSocket Binary data Λྲྀ͍ͨ͠! Base64 encode/decode ͘ͳΔ! Socket.IO x!
BinaryJS ͱ͔͋Δ͚Ͳɾɾɾ
ࣗ࡞ • ࡞ͬͯΈΑ͏ʂ • ༷ॻ http://tools.ietf.org/html/rfc6455 • WebSocket αʔόͷ࣮ͱϓϩτίϧ ղઆ
http://d.hatena.ne.jp/Jxck/20120725/ 1343174392 http://www.flickr.com/photos/60317050@N08/8735098936/
WebSocket server ͷ࣮ UPGRADE request! ͭͳ͗ͬͺͳ͠ͷ TCP ଓ! ͦͷதͰɺϓϩτίϧʹ४ڌͨ͠σʔλͷ ΓऔΓɻ
WebSocket Protocol 0: FIN+OPCODE, 1: Payload Length, 2-: Payload! 0:
FIN+OPCODE, 1: 0x7e, 2-3: Payload Length, 4-: Payload! ҎԼಉจ! socket ͷσʔλΛಓʹ 1byte ͣͭຒΊΔ/ಡ ΈऔΔ
Server! Client! Browser! HTTP Proxy Mobile! Safari Websit Adhoc Network
Web! Socket Web! Socket Websit Websit Architecture
TCP server as HTTP Proxy Browser ͔Βͷ request Λ TCP
server Ͱड͚ Δ! Binary ͷ·· WebSocket Ͱ server ! σʔλͷઌ಄ʹ 2 byte port ൪߸ΛՃ
TCP client as HTTP client WebSocket ͰૹΒΕ͖ͯͨ binary Λɺ࠷ॳͩ ͚
toString ͯ͠ host:port Λऔಘ! TCP ଓͨ͠Βɺޙͻͨ͢Β binary Λྲྀ͢
Keep-alive ͷ᠘ • ϒϥβϓϩΩγͱͷଓΛΒͣ ʹɺผͷϗετѼͷϦΫΤετΛૹͬ ͯ͘Δ! • ࠞઢʂʂʂ http://www.flickr.com/photos/hatm/5704687902/
HTTP server & client ʹ ͬͺΓϦΫΤετຖʹ header Λ parse ͠
ͳ͍ͱବͩͬͨ! HTTP request Λ parse ͢ΔͳΒ http.Server! Node ͷ HTTP parser native
ࠞઢΛ͙ Browser ͔Βͷ request ຖʹ 16 byte ͷ UUID ΛৼΔ!
Server ଆͰɺUUID Λͱʹࣝผ! ෳରԠͯࠞ͠ઢ͠ͳ͍ͣ
HTTPS CONNECT request! Socket ͔Βͷ data Λ browser ͔Β web
server ૉ௨͢͠Δ! ૉ௨͠ͳͷͰɺ҉߸Խ͞Ε͍ͯͯͳ͠
Demo
ײ TCP ͍͢͝ɻॱ൪อূ͞ΕͯΔ! όΠφϦʹগ͠׳Εͨ! Keep-alive ͳͲଓͷཧΉ͔͍ͣ͠! ंྠͷ࠶։ൃɺͳ͔ͳ͔ͪΌΜͱಈ͔ͳ͍͚ Ͳɺಈ͘ͱָ͍͠! ςβϦϯάΦϓγϣϯղͷಓԕ͍...
ࠓޙ HTTP tunneling: SSH Λ௨͍ͨ͠! Web αʔόͷಉ࣌ଓͷ੍ޚ