4

I want to build an MVC web application using sails.js.
I also want to have a mobile app and desktop client to connect to my web app. For connecting the mobile client I want to use socket.io since it gives realtime capabilities to it. How should I connect the client to the server?

I tried a socket connection from android client to one of the routes in my sails application and I got an error saying the connection had no cookies.

I remember in the past when I wanted to connect my desktop client to my Django app I got an error saying no POST possible when no csrf.

So my question is what is the right way of doing that? Should I send cookies to my mobile app? I don't think cookies are the clean way of doing this.

And what protocol should I use? Telegram uses MTProto. Should I implement something like that?

And where in an MVC web framework should I be listenig to and handling connection(s) from mobile and desktop clients?

For my app imagine an online store that also has social network capabilities and users can comment on store items from their phone client.

pjsofts
  • 170
  • 4
  • 18

1 Answers1

1

First of all, MTProto is a crypto protocol, so I'm not sure that you do really have to implement something like this.

If server app implemnting REST service, coockie are redundant, I think. Django POST forms handlers are awating csrf by default but it could be disabled or implemented without cookies (with extra post-param).

As far as I understand, you're trying to implement API for your service. Mobile apps usualy use API (and usualy REST API). I think it would be useful for you to read a few articles about REST API (you can start from here: http://www.restapitutorial.com/lessons/whatisrest.html)

Next you can search articles about implementiong of REST API with your framework (maybe this answer will help you http://www.restapitutorial.com/lessons/whatisrest.html).

Short and simple explanation: you need a set of server methods which will be API methods. For example GET method to /users url should return a list of users. POST to /users should create new user. And so on. And your app just making requests to these urls sending or receiving data. And you can make cryptography by encrypting and decrypting all transfered data. But you can use one of already existing protocols and you don't have to implement your own invent protocol.

Paul
  • 6,641
  • 8
  • 41
  • 56
  • What about the realtime part? I need Web socket connections, Also I expect the server to inform the client about the updates, instead of long polling which I suppose happens in REST. – pjsofts Oct 16 '15 at 04:00
  • I think for updates you can use push notifications. There are a lot of services for it. You can read more about it here: https://developers.google.com/cloud-messaging/ And about websockets you can read this: http://stackoverflow.com/questions/7445421/android-real-time-android-application-design – Paul Oct 16 '15 at 09:45
  • Does sails have a websocket pusher? If I use simple REST and a third party pusher, then I'll be bypassing all the realtime capabilities sails is promising. – pjsofts Oct 27 '15 at 08:14