Web Service sending information to mobile client - ios

I am looking to make an web application that allows to PUT ,GET etc from the client to the server. That is easy. However, if a certain event occurs on the serverside I would like to send information to the client. My clients will be mobile devices. I decided to use asp.net webapi. How should I handle sending information to the client. Should I use tcp sockets? What if the event occurs, and I need to send a json to the client, however the client has the application in suspended state. Can I buffer the messages and send it at the next socket connection?
Any insight would be greatly appreciated.
Thanks

Have you thought of trying WebSockets?. Since they are HTTP, you will not have much problems with things like firewalls. While its original intent was to be used in browsers, there seems to be libraries floating around for objective-c though I have not used any of them my self. One such library http://corner.squareup.com/2012/02/socketrocket-websockets.html

Related

MVC 5 Real-time SMS with SignalR

I am new to web development but I have a project done in VB6, it is a real time send and receive sms application. It uses a GSM modem connected to the server. My company asked me to make a web based version of my application, using ASP.NET MVC.
So I studied MVC about a month ago, created basic CRUD apps, read about SignalR but I don't want to start up a project that I am not confident if its feasible or not. So my question is, is this project possible with the said technology? (MVC, SignalR, and a GSM Modem)
If it is, can you point me somewhere I could start reading for maybe you know a similar project that can guide me through.
And if it is not, can you suggest me the appropriate tech to use for this project to be feasible? (I prefer ASP.NET MVC)
A little detail about the functionality of the project:
Has User Authentication - this user will have a simple "SMS box" type of thing which will update like a chatbox if an SMS is received in the GSM modem and this user can reply and use the GSM to send the SMS back to the sender.
IF anyone could help me, guide me, point me to some reading materials to make this project it would be greatly appreciated. Please post if you need clarifications and further explanation. Thanks!
User,
There are many ways to achieve this, so I will explain a method that worked for me a while back doing exactly this.
Based on the information provided, I will assume that you have a windows desktop app, that can already talk to the modem and perform various functions.
Trying to perform that same tasks in a web application can be a hard path to go down, what I opted for was rather simple in my opinion. You really have two separate problems, one is getting the received messages to the web application and the other getting the web application to send messages to the modem.
For handling received messages, I created a simple web api in the web application and defined a post method that is able to receive a sms object. You will need to provide the url for this call to your code that resides in your modem project, which I would convert to a windows service, if it is not already. Then when your code fires when the modem has received a sms, you simply create a object, serialize it to xml or json and then call the post method in your web api. This will give you the chance to use SignalR to notify clients or whatever else you might need to do. This is honestly is the simple part and you have the "real-time" handling ability now for receive.
For sending, there again where many options, I opted for database polling from the code inside the windows service, so when a user wants to reply or send a message, the message gets stored in a table in a database, from where the service code will pick it up and send it, once sent it will mark a field in the table as sent and possibly add a date and time as to when this happened. Again your service code could call another method on your web api, that will notify your app, that a message was sent and again you could notify the end user.
As for database polling, there are various methods, you could simply run some code every minute or some configurable value to see if there are any unsent messages.
You could use SqlDependency and handle the events in real time, you would register an event against the table where messages to be sent will be inserted into and when this happens, your service code will receive a real time event which can be handled.
You could also in the windows service, create a service, even a self hosted web api again, which can be called from your web application when it wants to send an email.
I did various implementations based on client requirements, but for me hosting either a wcf service or web api in the windows service project, proved to be the best in my opinion. You then simply have a configuration section in your web application, and provide the service address, or uri for the post method.
I hope that I have given you enough ideas to get a starting point for your project.

Single page apps keeping client and server in sync

I am trying to understand how single page apps spa's work.
My understanding of a spa is that you load the data on start-up and you use ajax calls for save etc, and the whole idea is that your models cache data on the client so you have a rich snappy experience in your browser.
I am confused as to how the client stays in sync with the server changes.
E.G. If I have multiple users logged into my spa and they are all making changes, how does my client know that another user has updated a persons details if it is using cached data?
My guess is that something similar needs to happen server side to update the client on a change. Does this exist or am I misunderstanding something?
Any help or pointers to additional info would be much appreciated.
Thank you in advance.
For server to client communication you can use SignalR.
SignalR allows you to create a hub on the server which you can then tell to update the clients.
It works with a fallback mechanism, it tries to use the following techniques and falls back onto the next one if it's not available in the browser:
Web Sockets
server sent events
forever frame
long polling
Link for fallbacks: http://www.asp.net/signalr/overview/introduction/transports-and-fallbacks
Link for signalR: http://signalr.net/

Restrict access to web service to only allow mobile clients

I'm currently building a mobile application (iOS at first), which needs a backend web service to communicate with.
Since this service will be exposing data that I only want to be accessed by my mobile clients, I would like to restrict the access to the service.
However I'm in a bit of a doubt as to how this should be implemented. Since my app doesn't require authentication, I can't just authenticate against the service with these credentials. Somehow I need to be able to identify if the request is coming from a trusted client (i.e. my app), and this of course leads to the thought that one could just use certificates. But couldn't this certificate just be extracted from the app and hence misused?
Currently my app is based on iOS, but later on android and WP will come as well.
The web service I'm expecting to develop in nodejs, though this is not a final decision - it will however be a RESTful service.
Any advice on best practice is appreciated!
Simple answer: You cannot prevent just anybody from acecssing your web site from a non-mobile client. You can, however, make it harder.
Easy:
Send a nonstandard HTTP header
Set some unique query parameter
Send an interesting (or subtly non-interesting) User Agent string
(you can probably think of a few more)
Difficult:
Implement a challenge/response protocol to identify your client
(Ab)use HTTP as a transport for your own encrypted content
(you can probably think of a few more)
Of course anybody could extract the data, decompile your code, replay your HTTP requests, and whatnot. But at some point, being able to access a free Web application wouldn't be worth the effort that'd be required to reverse-engineer your app.
There's a more basic question here, however. What would be the harm of accessing your site with some other client? You haven't said; and without that information it's basically impossible to recommend an appropriate solution.

Using XMPP as a push server?

I've been running around in circles the past few days trying to figure out a good solution for my problem. The main key here is that this is for an iOS application. What I want is to quickly communicate from one device to another device updates. So if user 1 performs an action, I want to, in real time, tell user 2 that user 1 has performed this action.
I don't want to use Apple Push Notifications for various reasons. So that's out of the question. I looked into services like Pusher and PubNub, but those are far too expensive (and only allow a ridiculously low number of concurrent connections, ~2500). I also looked into Google App Engine's Channel API, but it works through Javascript, and would have to be implemented using shady techniques on iOS. And honestly I'd rather not use that.
So now I'm looking into XMPP in Google App Engine. It seems like it would do what I want, but I'm not sure if I'm understanding the whole picture. Couldn't I accomplish what I wanted using XMPP messages, that is when user 1 performs an action, I can notify user 2 quickly with a JSON message?
The main key here is that I would have to perform user registration for XMPP behind the scenes, using the user's unique ID. Is this possible, to automatically and without user intervention create a Jabber ID like user-unique-id#my-app-engine-domain.com?
Overall, is this a feasible solution? What am I missing? What are some exceptions?
What you have described all sounds fairly easily doable with XMPP.
Just a couple of points.
You do realize, of course, it is XML based, so your JSON messages would be embedded within XML stanzas, with appropriate escaping when necessary.
Your user registration would be determined by the server implementation, but I believe most will allow custom authentication hooks (like LDAP). So having an external registration mechanism shouldn't be a problem and is a fairly common approach.
Since you are using ios, you should be looking at XMPPFramework as your XMPP library.
Depending on your use case, you may want to look at XMPP pubsub as well for your updates, depending on how many other devices are supposed to get the message when one makes a change. I have used this approach and it works well for real time client to client updates.
AppEngine supports XMPP only as client: it can send and receive messages. The key here is if you look at the docs for sending XMPP message, that every client needs to have it's own address (JID) which is not provided by GAE.
So to support your situation, you would need to have an external XMPP server, where every client gets it's own JID and then you can send XMPP messages to them.

Client/Server Application for iOS

I have had experienced with iOS development but no Client Server type applications.
I have heard about HTTPS, REST, JSON, etc. I am confused on the differences.
My app that I want to build is getting a list of data to output to the user and also sending a form to the server to be processed. E.g. A Membership Application to the Server with personal information and other pertaining information to be stored in the server. I also need the connection to be secure and the user must logon to the server with a username and password.
How does my app communicate with the server? Is it using NSURLRequest?
What is the best method or protocol to accomplish this?
Thanks!
HTTPS, REST, and JSON are different tools you can use when performing networked operations (more specifically, a secure protocol, a web service architecture, and a method of object serialization, respectively). If you don't know what these mean, I would do a little reading before attempting to build an iOS app that functions as a client. The link johnathon posted in the comments is a little low-level for what you're wanting to do, but searching around for "consuming a web service with iOS" might be good.
Also, does the service already exist? If so, your task is essentially to understand how to communicate with the server.
Once you're a little more up-to-speed on the fundamentals, however, the AFNetworking library is phenomenal.

Resources