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
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
940
watsonx.ai Dojo #6 継続的なAIアプリ開発と展開
oniak3ibm
PRO
0
170
週次リリースを実現するための グローバルアプリ開発
tera_ny
1
1.2k
QA環境で誰でも自由自在に現在時刻を操って検証できるようにした話
kalibora
1
140
React 19でお手軽にCSS-in-JSを自作する
yukukotani
5
560
盆栽転じて家具となる / Bonsai and Furnitures
aereal
0
1.9k
GitHub CopilotでTypeScriptの コード生成するワザップ
starfish719
26
6k
混沌とした例外処理とエラー監視に秩序をもたらす
morihirok
13
2.3k
.NETでOBS Studio操作してみたけど…… / Operating OBS Studio by .NET
skasweb
0
120
毎日13時間もかかるバッチ処理をたった3日で60%短縮するためにやったこと
sho_ssk_
1
550
為你自己學 Python
eddie
0
520
선언형 UI에서의 상태관리
l2hyunwoo
0
270
Featured
See All Featured
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Making Projects Easy
brettharned
116
6k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.3k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
Mobile First: as difficult as doing things right
swwweet
222
9k
Scaling GitHub
holman
459
140k
Raft: Consensus for Rubyists
vanstee
137
6.7k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
Building an army of robots
kneath
302
45k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
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 αʔόͷಉ࣌ଓͷ੍ޚ