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
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
CSC509 Lecture 09
javiergs
PRO
0
140
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
190
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
120
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
340
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.1k
Figma Dev Modeで変わる!Flutterの開発体験
watanave
0
140
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
Macとオーディオ再生 2024/11/02
yusukeito
0
370
Featured
See All Featured
GraphQLとの向き合い方2022年版
quramy
43
13k
A Philosophy of Restraint
colly
203
16k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Site-Speed That Sticks
csswizardry
0
28
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
Docker and Python
trallard
40
3.1k
Why Our Code Smells
bkeepers
PRO
334
57k
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 αʔόͷಉ࣌ଓͷ੍ޚ