하위 프로토콜, 확장 기능 및 압축
애플리케이션 하위 프로토콜을 협상하고 메시지별 압축과 같은 확장 기능을 활성화하며 WebSocket 프로토콜을 더 깊이 이해합니다.
하위 프로토콜, 확장 기능 및 압축은(는) CoddyKit의 무료 WebSockets & Realtime Systems Programming 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 WebSockets & Realtime Systems Programming 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. WebSockets & Realtime Systems Programming 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Beyond the Basics
The raw WebSocket protocol only moves bytes. Two negotiation mechanisms let you layer meaning and efficiency on top: subprotocols and extensions.
What Is a Subprotocol
A subprotocol is an agreed application-level message format, like a contract for what the bytes mean. Examples include wamp, mqtt, and graphql-ws.
Requesting a Subprotocol
The client lists desired subprotocols in a handshake header.
Sec-WebSocket-Protocol: graphql-ws, jsonServer Selection
The server picks one subprotocol it supports and echoes it back. If none match, it omits the header and only the base protocol applies.
Sec-WebSocket-Protocol: graphql-wsSubprotocols in the Browser
Pass an array of subprotocol names as the second argument when opening the socket.
const ws = new WebSocket('wss://api.example.com', ['graphql-ws', 'json']);
console.log(ws.protocol); // the one the server choseWhat Is an Extension
An extension changes how frames are transmitted at the protocol level, transparent to your application logic. The most common is per-message compression.
Negotiating Extensions
Extensions are negotiated in the handshake too, via their own header.
Sec-WebSocket-Extensions: permessage-deflatePer-Message Deflate
permessage-deflate compresses each message with DEFLATE before sending. It cuts bandwidth for text-heavy payloads at the cost of CPU.
When Compression Helps
Compression wins for large, repetitive JSON or text. For tiny or already-compressed payloads (images, binary), it adds overhead without benefit and can be disabled.
Subprotocol vs Extension
Keep them straight:
- Subprotocol: meaning of the messages (application layer)
- Extension: how frames are transported (protocol layer)
Practical Notes
Both are negotiated only during the handshake and cannot change afterward. Always verify ws.protocol client-side so your code parses messages with the agreed format.
Quick Check
Test your protocol knowledge.
Recap
You explored advanced WebSocket negotiation:
- Subprotocols agree on message format via
Sec-WebSocket-Protocol - Extensions change frame transport via
Sec-WebSocket-Extensions permessage-deflatecompresses text payloads- Both are fixed at handshake time
You now understand the negotiation layer of WebSockets.
자주 묻는 질문
“하위 프로토콜, 확장 기능 및 압축” 강의는 무료인가요?
네 — “하위 프로토콜, 확장 기능 및 압축” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 WebSockets & Realtime Systems Programming 강의 전체를 잠금 해제할 수 있습니다. WebSockets & Realtime Systems Programming 강의에는 총 4개의 강의가 포함되어 있습니다.
“하위 프로토콜, 확장 기능 및 압축”에서 뭘 배우나요?
애플리케이션 하위 프로토콜을 협상하고 메시지별 압축과 같은 확장 기능을 활성화하며 WebSocket 프로토콜을 더 깊이 이해합니다. 브라우저에서 직접 실행하는 실습 코드로 WebSockets & Realtime Systems Programming을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
WebSockets & Realtime Systems Programming을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 WebSockets & Realtime Systems Programming은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.
“하위 프로토콜, 확장 기능 및 압축” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 WebSockets & Realtime Systems Programming 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 WebSockets & Realtime Systems Programming 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- WebSocket 핸드셰이크 해설
- WebSocket 데이터 프레이밍과 메시지
- 연결 수명 주기와 상태
- 하위 프로토콜, 확장 기능 및 압축