1

I am going to use sails to set a web application base on socket.io

The problem is the socket connection is always re-established after a route forward.

For example :

When I enter /index, the socket is well connected. Then I click a link to /news, I found the socket is disconnected and re-connected again.

Need I store the connection in the server side ? Any suggestion or answer is appreciated.

Michael
  • 402
  • 1
  • 3
  • 16
  • Using [io.socket.get](http://sailsjs.org/#/documentation/reference/websockets/sails.io.js/socket.get.html) when loading content from /news should solve this, however there might be a built-in solution I'm not aware of. – Howie Sep 01 '14 at 12:10
  • @Howie I agree with you that built-in solution must be in somewhere. – Michael Sep 02 '14 at 03:59
  • possible duplicate of [How to maintain a WebSockets connection between pages?](http://stackoverflow.com/questions/10886910/how-to-maintain-a-websockets-connection-between-pages) *Hint: you can't.* – sgress454 Sep 02 '14 at 17:05
  • If the web application is a single-page app, it's doable. The question now is, whether sails.js provides any higher-level solutions that handles page navigation. The answer to that question would probably be: use AngularJS or Backbone with sails.js. – Howie Sep 03 '14 at 06:33
  • @Howie clearly it's not a single-page app; that's the whole issue. As far as Sails providing solutions for page navigation: Sails is a back-end framework. The front-end frameworks you mentioned are both good solutions to the problem at hand. – sgress454 Sep 03 '14 at 16:57
  • @sgress454 thanks for your link. I can't stop user open another new window by using right click event it's a single page app. So I am going to replace socket with interval ajax pulling in my app. – Michael Sep 04 '14 at 00:52

0 Answers0