๐ฑ WebSockets๋ฅผ 5์ด ์์ด์๊ฒ ์ค๋ช ํ๋ฏ
Source: Dev.to
๋ฌธ์ ๋ฉ์์ง vs ์ ํ ํตํ
๋ฌธ์ ๋ฉ์์ง (HTTP)
- ๋ฉ์์ง๋ฅผ ๋ณด๋ ๋๋ค
- ๋ต์ฅ์ ๊ธฐ๋ค๋ฆฝ๋๋ค
- ๋ํ ์ข ๋ฃ
- ๋ค์ ๋งํ๊ณ ์ถ๋์? ๋ ๋ค๋ฅธ ๋ฉ์์ง๋ฅผ ๋ณด๋ด๊ณ ๊ธฐ๋ค๋ฆฝ๋๋ค
์ ํ ํตํ (WebSocket)
- ํ ๋ฒ ์ฐ๊ฒฐํฉ๋๋ค
- ์ธ์ ๋ ์๋ฐฉํฅ ๋ํ ๊ฐ๋ฅ
- ์ฆ์ ์๋ต
- ๋์ ๋๊น์ง ์ฐ๊ฒฐ ์ ์ง
HTTP์ ๋ฌธ์ ์
์ผ๋ฐ ์น ํ์ด์ง๋ HTTP๋ฅผ ์ฌ์ฉํฉ๋๋ค:
Browser: "Any new messages?"
Server: "Nope"
(1 second later)
Browser: "Any new messages?"
Server: "Nope"
(1 second later)
Browser: "Any new messages?"
Server: "Yes! Here's one!"
์ด๋ ๋งค์ด โANY NEWS?!โ ๋ผ๊ณ ๋๊ตฐ๊ฐ์๊ฒ ๋ฌธ์ ๋ณด๋ด๋ ๊ฒ๊ณผ ๊ฐ์โ์ง์ฆ๋๊ณ ๋นํจ์จ์ !
WebSocket ํด๊ฒฐ์ฑ
Browser: "Let's open a phone line"
Server: "Connected! โ
"
(Server gets a new message)
Server: "Hey! New message for you!" (instantly pushes)
(Browser sends a message)
Browser: "Sending this!" (instantly sent)
์์ชฝ ๋ชจ๋ ์ธ์ ๋ ๋ํํ ์ ์์ต๋๋ค. ๊ธฐ๋ค๋ฆด ํ์ ์์. ๊ณ์ ๋ฌผ์ด๋ณผ ํ์๋ ์์.
์ด๋์์ ๋ณผ ์ ์๋์
- ๐ฌ ์ฑํ ์ฑ (WhatsApp, Discord)
- ๐ ์ฃผ์ ํฐ์ปค (์ค์๊ฐ ๊ฐ๊ฒฉ ์ ๋ฐ์ดํธ)
- ๐ฎ ๋ฉํฐํ๋ ์ด์ด ๊ฒ์ (์ค์๊ฐ ์ก์ )
- ๐ ์๋ฆผ (์ฆ์ ์๋ฆผ)
- ๐ Google Docs (๋ค๋ฅธ ์ฌ๋์ ํ์ดํ์ ์ค์๊ฐ์ผ๋ก ๋ณด๊ธฐ)
ํ ๋ฌธ์ฅ์ผ๋ก
WebSocket์ ๋ธ๋ผ์ฐ์ ์ ์๋ฒ๊ฐ ์ธ์ ๋ ์ฆ์ ๋ํํ ์ ์๋๋ก ์ค์๊ฐ ์ฐ๊ฒฐ์ ์ด์ด ๋์ด, ๊ธฐ๋ค๋ฆด ํ์๊ฐ ์์ต๋๋ค.