Emitting a message in sails v0.11 (client-side)

前端 未结 1 564
情书的邮戳
情书的邮戳 2020-12-11 06:43

I\'m having some issues with the newest version of sails.js (0.11.0). It stated in github that plain socket.io code will be accepted and ran in sails.js; however, I am simp

相关标签:
1条回答
  • 2020-12-11 06:58

    You are correct in that the recommended way of communicating with the server via sockets is to use the RESTful socket client methods. The benefit is that you can use the regular Sails routing and controller/action architecture for socket communication instead of having to support a whole other layer of subscription and event-handling on the backend. This is one of the main reasons why @mikermcneil originally created Sails. Two things to note:

    1. You can use req.isSocket in your controller action to determine whether the request is coming from a socket, and
    2. You can get the raw, underlying socket.io instance on the client with io.socket._raw, which will have the emit method. But again, this is not the recommended practice.
    0 讨论(0)
提交回复
热议问题