Remote Control for Website - websocket

I want to start to create a website which is opened on a mobile phone (any kind of smartphone). This website will have the feature to control a website you have already opened on your computer. (The Volkswagen New Century Beetle from 2011 had the feature, that i could scroll via smartphone on the website opened on my desktop computer)
We have a streaming website for horsevideos, and this will be an awesome feature for our customers, if they could watch the streams on their smart tv and control via iphone/android/wp.
Also wilmaa.com from switzerland provides a remote control for smartphone to navigate on my website on smart tv/webbrowser.
Because I need a starting point to learn how it works i was checking Google, maybe there already any remote controls outside, but unfortunately i couldn't find anything.
Maybe Stack Overflow can help me by giving some starting points on how to realize this.

To do this you need some kind of 'pushing' service able to overcome the inherent drawback of HTTP that it has always been a 'pull only' system - client initiates a request, server answers. In this case you want to push an event from the server to the client.
For the past years this has been done with so called 'long polling'. This means that you 'abuse' the mechanism present in browsers that protects the server from hanging requests, but allows them to take a while. Apache is by default configured to allow a request to last 300 seconds on most platforms. Long polling works by sending an Ajax request, and if the server has no data, instead of sending that back it just waits, until either it does have data, or a long period such as a minute has expired. The client does not send a new request until it has received a response. This gives the illusion to the end user of real time feedback, and is how sites like Facebook et al have done this for years.
Since a few months it's also possible to employ a new HTML5 technology that now has stable implementations on all major browsers: Websockets. This technology allows a server to upgrade a common pull request to a full bidirectional connection, allowing realtime communication between browser and server. Regrettably, the 'regular' webservers such as Apache are not really built for this kind of logic, although it is possible to emulate it with frameworks like Ratchet. For the realtime part of the system the current platform of choice for most sites, including Stack Overflow here, is node.js - serverside asynchronous Javascript.
What I would recommend in your situation:
Set up a separate node.js server as an event dispatcher (you can get a cheap micro sized EC2 instance at Amazon for like $15 per month which will probably suffice, and is very scalable)
Keep all the other code in the regular environment where it is now, just add logic to communicate with the event dispatcher
Deploy Socket.io as your websocket handling service. It simplifies all the Javascript logic on both server and client side, and wraps a realtime connection in such a way that it's even compatible with IE5.5, by gracefully degrading towards technologies that are supported by both server and client - websockets on recent browsers, long polls or other technologies on legacy systems.
With this solution you can easily implement, with relatively little code, a system with full realtime responsiveness across multiple platforms as you described.
As for the controlling app itself, just use HTML5, with Phonegap if you intend to distribute to app stores.

Related

Send info to client on server event

I am trying to create a shared calendar as a web app. When someone adds an event on the calendar i want everyone who shared that calendar to see that event too. When someone create an event, I made an ajax that sends the data to a database. Is there a way to send the event from server to other clients that are online on the page and share the same calendar? I did it now by constantly 'refreshing' the info from database.
If anyone has a clue how this can be made, please tell me.
Wanting a web server to "push" information back to the browser is a time old issue. The traditional way to handle this is to have any active clients (i.e. the people still logged into your app with a page open) continuously "poll" the server at a regular interval to see if there's any new information for it. In your case, you can have some JS on the page make an AJAX call every 10 seconds to see if they have any new calendar events they should be aware of. This does increase the overall traffic to your web server so pick your polling time appropriately - otherwise you'll cripple your web server because it will spend all of its time handling these "is there anything new?" requests when most of the time there won't be.
If you want to be a little more cutting edge, you can look at HTML5 websockets. A google search for "html5 websockets tutorial" should give you plenty of resources. They're a bit trickier to use and require that you are running a web server that supports them (you probably are). For browsers that support it, you can maintain a more long term open connection where you can then push data from the web server back to the browser like you want to and your JS will capture "onmessage" events with the updated info. Pointing you at google isn't trying to flake out of a more complete answer, but there's already a number of excellent tutorials out there so look for HTML websockets and you should be able to pull off what you're looking to do.

broadcasting data to mobile devices

I working on a project were mobile users can receive alerts based on diferent factors, the server side will be implemented using the MVC framework.
My question is regarding the client side; what would be the most efficient way to send the alerts to the clients? is there any way to broadcast the alerts to each device or do I have to set up some system where each device pulls the data from the server on an interval of mins/seconds? I am afraid pulling the data every X secs/mins would create an unnesesary overhead on the mobile devices.
One way would be using SMS but SMS gateway services are expensive and not on my budget right now.
I haven't personally tried it, but this service might work for you:
http://www.airgramapp.com/api
It is free for limited use. Downside is it appears to be a separate install on the mobile device. This might means less control of the content of the message or its look. Upside is it looks quick and easy if you just need a proof of concept at this point.

Receiving pushed messages from web service

I am working as part of a team using Android and WP7 to create apps that communicate with a server. So ideally we want a consistent approach to receiving the data from the server.
I currently am using HTTPWebRequest to form a SOAP message and send it to a Java-based web service to receive messages (Adding as a ServiceReference didn't work no matter what I tried) At the moment it's a simple case of receiving the full list of things and just recreate the list each time via DespatchTimer to do periodic calls. But of course periodic pollin is likely to be ratehr battery intensive so not the best apporach for my needs.
I now need to change the code so that changes are pushed rather than polled. The team is looking at XMPP to do this as Android libraries are readily available to do this but I am having trouble finding open source libraries to do this.
Microsoft Push seems available but this appears to require a Microsoft based server side environment to push unless I have misinterpreted this? Or even if push notifications are a sensible way to do this.
So what I would like to know is the approach to handling pushed messages in this scenario which i hope someone out there has had experience in
Thanks
Microsoft Push Notification System [MPNS] does not require a MSFT-based server backend. It simply relays the Push Notifications through carrier or other data channels to subscribing phones. You should be able to make HTTP POST requests to MPNS at the Windows Phone subscriber Channel URI & MPNS would deliver the Push Notifications for you. Your server side can be anything, as long as you able to make the HTTP requests.
A good starting point can be found here.
Hope this helps!

What is the best solution for real-time bi-directional communication between a web application running on a mobile phone and a server?

I'm looking at having thousands of simultaneous connections from mobile phones to the server whereby anytime a user interacts with his cell phone, the data is sent and logged by the server. Also, anytime the server has new information for that user, the server can push that information without a browser refresh. I am wondering what is more stable and how you would build this?
A good real-time framework or infrastructure will have numerous APIs that should let you connect any device, no matter the technology, to the real-time server e.g. an iOS client library for iPhone and iPad, a JavaScript client library for numerous platforms including normal and mobile web, an Android compatible Java library and so on.
An interesting idea might be to choose which ever framework or real-time service suits your needs best and then using something like PhoneGap. But, as #rt2088 says, it depends if you need the notification app to be running as a service on the phone or as a standalone application.
The choice will also depend on whether you want to install, host, maintain and manage the scaling of your own real-time services or not. If not, there are a number of services out there who you could use so you can concentrate on building your application. If you do want to manage your own infrastructure then the Comet Maturity guide could be a good start. It's a little out of date but is still probably the best reference available.
the ability to push new content the
user based on his GPS location which
is "pinged" to our server. Based on
that, we deliver local content. What
frameworks are you talking about?
There are a number of real-time frameworks available at the moment. Some are hosted services and others require installation on your own hardware. The majority of them will come with a bunch of libraries in different technologies that make it easier to get up and running with them e.g. a JavaScript library that wraps the WebSocket object and also manages fallback for web browsers that don't support WebSockets.
I've just created a Real-Time Technologies Guide in which I've listed all the real-time technologies that I could think of and provided a bunch of tags associated with each.
wouldn't a javascript client library
cover all platforms if it is a web
appilcation?
If the application is a web application then yes, a JavaScript library would be all you need for the client application. The server side libraries that you require would depend on the real-time technology you choose.
Best solution to achieve this is to use the WebSocket communication. It is bidirectional asynchronous communication. Currently every browser supports this new standard and plenty of code snippets available. You just have to google it. There are many server and client side frameworks. choose the one best suits to your requirement.
The details of the WebSocket specification is available at -
Websocket specification
Do you need notification when user uses mobile browser of handset or the mobile handset itself (performing non-browser tasks)? Based on that, the framework to record user activity can be selected.

Using Jabber to send network messages

(Also asked over on ServerFault, where I was advised to post it here too)
We have a requirement to send desktop alerts to various users (compliance, production) across a network when other users have submitted content online for a report.
At present we are using NET SEND but this has no guarantee of delivery and has proved unreliable from both client and server perspective (and I gather will be unsupported in later versions of Windows; we are currently running XP).
We are considering a Jabber-based solution but has anyone used a Jabber client to pop up alert messages on the screen like NET SEND does, as opposed to just bringing a chat window to the front or displaying a temporary 'toast' message near the system tray.
We need the alert message to be persistent and only dismissed by the user, indicating they have seen it. Toast-style pop-ups would be fine as long as it was not only for a limited time and again had to be dismissed by the user.
Any solutions?
Openfire is a java based Jabber server that seems to be targeted to a corporate/business environment and provides the "toast" message feature with their Spark client. They also offer several other useful business-focused features.
Offline message delivery is not guaranteed by XMPP specification. It depends on concrete server implementation. Moreover, it has cost in supporting user accounts.
As an out-of-box solution it is fine, but since we are in development community, I would
consider building alert system using MessageQueue for guaranteed delivery.
The message-delivery semantics of XMPP are liable to be a good fit for your application, since you're not talking about financial transactions that require fiduciary-level delivery guarantees. It will certainly be better than NET SEND by a lot.
Write a simple client that listens for messages and does the pop-ups in whatever format you want, and have the program run in the background, perhaps with a tray icon. Writing something like that with Jabber-Net would be the work of a few hours, for example.

Resources