LoginSignup
4

More than 3 years have passed since last update.

Socket.IOとWebSocketは通信できない

Posted at

Socket.IOとWebSocketは通信できない

タイトルの通りです。
Node.jsでWebSocketサーバを作る機会がありまして、有名なSocket.IOを採用しました。
私のSocket.IOの認識は以下でした。

  • WebSocketをラップしたライブラリで、接続できないときはポーリングなどに自動で切り替えてくれる
  • 普通のWebSocketサーバとも通信できる

しかし、実際にはSocket.IOはSocket.IOとしか通信できません。
改めて公式を見ると、ちゃんと書いてあります。
WebSocketクライアントとSocket.IOサーバの通信、あるいはその逆は、不可と読めますね。

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 some metadata to each packet: the packet type, the namespace and the ack id when a message acknowledgement is needed. 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 WebSocket server either. Please see the protocol specification here.

常識なのかもしれませんが・・・
他に間違える人が少しでも減るよう、記事として残しておきます。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4