最終更新:2022-09-12 (月) 15:20:38 (593d)
Socket.IO/WebSocketとの違い
What Socket.IO is not
- Socket.IO is NOT a WebSocket implementation.
- Although Socket.IO indeed uses WebSocket as a transport when possible, it adds additional metadata to each packet.
- That is why a WebSocket client will not be able to successfully connect to a Socket.IO server, and a Socket.IO client will not be able to connect to a plain WebSocket server either.
Here are the features provided by Socket.IO over plain WebSockets:
- reliability (fallback to HTTP long-polling in case the WebSocket connection cannot be established)
- automatic reconnection
- packet buffering
- acknowledgments
- broadcasting to all clients or to a subset of clients (what we call "Room")
- multiplexing (what we call "Namespace")
WebSocketのサーバ
メモ
- ws が全クライアントに送信するにはクライアントの台数分ループを回す必要がありますが、Socket.IO は1回の操作で全クライアントに送信することができます。
- ws はデータをそのまま送信しますが、Socket.IO は socket.emit() の第1引数にイベント名をつけて送信することができます。