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
840
Building a Pixel Art Editor with Elm
shuhei
1
750
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
840
Angular 2 @ JS Ojisan #6-3
shuhei
1
3k
Introduction to Angular 2
shuhei
2
140
Other Decks in Programming
See All in Programming
月刊 競技プログラミングをお仕事に役立てるには
terryu16
1
1.2k
rails newと同時に型を書く
aki19035vc
5
710
サーバーゆる勉強会 DBMS の仕組み編
kj455
1
300
Rubyでつくるパケットキャプチャツール
ydah
0
170
カンファレンス動画鑑賞会のススメ / Osaka.swift #1
hironytic
0
170
ISUCON14感想戦で85万点まで頑張ってみた
ponyo877
1
590
PHPカンファレンス 2024|共創を加速するための若手の技術挑戦
weddingpark
0
140
Flatt Security XSS Challenge 解答・解説
flatt_security
0
740
責務を分離するための例外設計 - PHPカンファレンス 2024
kajitack
9
2.4k
ErdMap: Thinking about a map for Rails applications
makicamel
1
660
PicoRubyと暮らす、シェアハウスハック
ryosk7
0
220
Запуск 1С:УХ в крупном энтерпрайзе: мечта и реальность ПМа
lamodatech
0
950
Featured
See All Featured
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Being A Developer After 40
akosma
89
590k
Testing 201, or: Great Expectations
jmmastey
41
7.2k
The Cost Of JavaScript in 2023
addyosmani
46
7.2k
We Have a Design System, Now What?
morganepeng
51
7.3k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Facilitating Awesome Meetings
lara
51
6.2k
Speed Design
sergeychernyshev
25
740
How to Ace a Technical Interview
jacobian
276
23k
Code Review Best Practice
trishagee
65
17k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
Optimising Largest Contentful Paint
csswizardry
33
3k
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 αʔόͷಉ࣌ଓͷ੍ޚ