WebSockets(ウェブソケット)

単一のTCP接続を介してフルデュプレックス(全二重)通信チャネルを提供する通信プロトコル。

サーバーからクライアントへのプッシュ通信が可能になり、ポーリングなどの古い手法に代わる標準的な技術となっています。

        graph LR
  Center["WebSockets(ウェブソケット)"]:::main
  Rel_websocket["websocket"]:::related -.-> Center
  click Rel_websocket "/terms/websocket"
  Rel_http["http"]:::related -.-> Center
  click Rel_http "/terms/http"
  classDef main fill:#7c3aed,stroke:#8b5cf6,stroke-width:2px,color:white,font-weight:bold,rx:5,ry:5;
  classDef pre fill:#0f172a,stroke:#3b82f6,color:#94a3b8,rx:5,ry:5;
  classDef child fill:#0f172a,stroke:#10b981,color:#94a3b8,rx:5,ry:5;
  classDef related fill:#0f172a,stroke:#8b5cf6,stroke-dasharray: 5 5,color:#94a3b8,rx:5,ry:5;
  linkStyle default stroke:#4b5563,stroke-width:2px;

      

🧒 5歳でもわかるように説明

つなぎっぱなしの電話のようなものです。いちいちかけ直さなくても、お互いにいつでもすぐに話せます。

🤓 Expert Deep Dive

RFC 6455で規定されており、HTTPのオーバーヘッドを解消します。チャット、取引、ゲームなどのリアルタイム性が要求されるWebアプリに不可欠です。WSSによる暗号化が推奨されます。

❓ よくある質問

Is WebSocket better than HTTP?

For real-time data, yes. For static content or standard web pages, HTTP is more efficient.

Does WebSocket use a port?

It typically uses port 80 for WS and 443 for WSS, shares with HTTP.

📚 出典