진짜 양방향, persistent
WebSocket 은 양쪽이 자주, 비동기로 message 보내야 할 때 손이 가. handshake 끝나면 어느 쪽이든 아무 때나 쓸 수 있어. 'request' 나 'response' 개념 없어 — frame 이 양방향으로 흐르는 단일 TCP connection, 누가 닫을 때까지 열려있어.
Upgrade handshake
WebSocket 은 특별한 헤더 가진 HTTP/1.1 GET 으로 시작해. 서버가 101 Switching Protocols 로 답하면 같은 socket 이 HTTP 그만 말해. 그 순간부터 wire 위 바이트는 RFC 6455 가 정의한 WebSocket frame 이야.
ws:// vs wss://
ws:// 는 unencrypted (port 80 default), wss:// 는 TLS-wrapped (port 443). production 에선 무조건 wss://. 많은 proxy 와 corporate firewall 이 unencrypted WebSocket 그냥 떨어뜨려. 정책 빼고 봐도 chat 이나 auth token 을 cleartext 로 넘기고 싶지 않을 거야.