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
830
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
830
Angular 2 @ JS Ojisan #6-3
shuhei
1
3k
Introduction to Angular 2
shuhei
2
140
Other Decks in Programming
See All in Programming
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
120
あれやってみてー駆動から成長を加速させる / areyattemite-driven
nashiusagi
1
200
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
930
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
140
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
300
menu基盤チームによるGoogle Cloudの活用事例~Application Integration, Cloud Tasks編~
yoshifumi_ishikura
0
110
42 best practices for Symfony, a decade later
tucksaun
1
180
Haze - Real time background blurring
chrisbanes
1
510
RWC 2024 DICOM & ISO/IEC 2022
m_seki
0
210
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
180
モバイルアプリにおける自動テストの導入戦略
ostk0069
0
110
創造的活動から切り拓く新たなキャリア 好きから始めてみる夜勤オペレーターからSREへの転身
yjszk
1
130
Featured
See All Featured
Bash Introduction
62gerente
608
210k
A Modern Web Designer's Workflow
chriscoyier
693
190k
A Philosophy of Restraint
colly
203
16k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
The Cost Of JavaScript in 2023
addyosmani
45
7k
Fireside Chat
paigeccino
34
3.1k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.3k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
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 αʔόͷಉ࣌ଓͷ੍ޚ