How can COMET/ Server Push be achieved on Google app engine? - java

I am new to both Stack overflow and Google app engine.
in a Java Web application, how ddo I achieve COMET, are there limitations in terms of connection timeout or if that is not possible, can a websocket server be implemented on appengine ?

If you need server-to-client push, you have to use Channel API for GAE.
It not a COMET or WebSockets, technically, but it's same. And, I guess, I'll be functioning as a web sockets, sometimes in future (maybe it's already working, but i don't know where to get a browser that supports this feature, right now. Can anyone correct me there?). Btw, for you it'll be still same Channel API

Related

What is the best way to implement push server-side app for android?

I'm developing an Android app that requires 2 (or more) devices to communicate with each other.
I tried using Google Cloud Messaging but I was disappointed to find out that the GCM max capacity is 100 messages, so it is broken and does not fit my requirements.
I was thinking about java sockets. Every device will open a new socket (or keep its socket open) and communicate with a group of sockets (devices).
In order to communicate this way I need a server-side app that can send messages to the client (android device). So I figured out that HTTP or web-service won't help me. Am I right?
What is the best way for me to implement such a server-side app?
You can refer to this question I previously asked and implemented. It was for implementing my own Notification mechanism but it equally (or even more) applies to chatting applications since message queues perfectly fit that usecase.
Building an Android notification server
I ended up not doing it and using GCM at the end but I did have a fully working solution using ActiveMQ and Paho. You can research them both and understand their inner workings. It's easy in principle and definitely possible but the problem is, you may not be able to do this for iOS or WP as it requires running a service in the background (in case your app is not open and you want to make sure the messages are at least sent in a notification).
The possible solution to that problem would be to use both the notification service (GCM or equivalent) for background notifications and then using your MQ for actual communication but I decided that was too much for my project.
If you look at Paho, it will have a fully working MQTT solution that will work even if the phone is not "online" (sleeping or otherwise) and there are plenty of samples for ActiveMQ and drivers for multiple programming languages.
I think this solution is much better than having open sockets between two apps, at least because they allow you to persist messages and guarantee delivery which is an important aspect for a chatting application.
As it is said by kha, choose one of the message queue protocols is the best solution. 3 reasons in brief,
Delivery guaranteed regardless of temporary offline or long latency.
As simple as subscribe / publish, no worry about transport layer any more.
Broker available online. You save time and money for setting up your own.
For mobile devices like in your case, I'd prioritize MQTT too. It's lightweight and stable. If you are totally new to message queue or MQTT, refer to this documentaion and example code

iOS - JAVA Best approach to Achieve Real-Time Data sync

We are developing an app that will have Web service in JAVA and Application in iOS.
Web-service will compute the list on a Particular Algorithm and that list has to be Shown realtime on the Device.
We were thinking of making a Routine Post Calls on every minute and get result from server but I think this would be very Costly and inappropriate way for syncing data with the Web-service's Result.
Can anyone provide Best alternative and Ideal Way for such type of requirement. Which approach should we choose to Provide such Real-time Sync for application.
You can use a WebSocket connection for this. WebSocket establish a full duplex connection between iOS and your server. This allows the server to trigger the client if new data is available.
As you mention it doing a routine post call every minute could work, but it will cost a lot of resources. It's not a good solution.
One solution could be to use websocket. So the server will send notification when data have changed. See here what is websocket http://fr.wikipedia.org/wiki/WebSocket
Use netty-socketio java realtime framework, it supports long-polling and websocket transports. javascript, ios, android client libs also available.
After googling and research, I found Socket.io better option for Our case
Socket.IO is a WebSocket API created by Guillermo Rauch, CTO of LearnBoost and lead scientist of LearnBoost Labs.
Socket.IO will use feature detection to decide if the connection will be established with WebSocket, AJAX long polling, Flash, etc., making creating realtime apps that work everywhere a snap. Socket.IO also provides an API for Node.js which looks very much like the client side API.

Could I use Google App Engine to host a Java IRC Bot?

I have an IRC bot written entirely in Java that I've been hosting on my home computer, but my iffy internet connection has been disconnecting it a lot. I've been wondering if I could use the Google Apps Engine to host the bot with a constant connection? If so, what kind of changes am I going to have to make?
Thanks for the help
No, you cannot do that. Google App Engine does not allow arbitrary outgoing Socket connections (probably because they do not want people using their platform as a proxy server). The closest thing they offer is the URL Fetch API for accessing external content over the network/Internet.
Using that, you might be able to come up with something that drives an existing web-based IRC client using an App Engine app. Though I'm not sure what benefit that would have over just using a web-based IRC client directly.
Also you cannot have a "constant connection" to (or from) an App Engine app. The platform will automatically time-out/close any request that has not completed processing within about 30 seconds or so.

Is it possible to use WebSockets or similar with a native Android application?

I have a Node.js app that uses HTTP / REST (using Express.js), and a native Android application that communicates with this. This works fine.
I am now looking at writing a more real-time version, which can push messages to a native client. Unfortunately, it needs to be a native client, as there is some fairly complex work done with the data that simply will not be possible in a mobile browser for the forseable future (otherwise I would just wait for WebSockets support to appear in the Android browser).
So, my question is what are my options?
I know about the Android Cloud to Device Messaging framework, but this requires registration and a Google sign-in, and I would much prefer the server to be client agnostic.
Is there a reliable WebSocket client that I can use (ideally) to talk to a Node.js server running Socket.io? Or any other native method (using the NIO classes)?
See Java socket.io client
you could use https://github.com/koush/android-websockets. It is also mentioned in the socket.io wiki pages
PS: i know it is a bit late to respond to this post, but this for other like me who didn't find an answer to question like this.
compile node.js on Android natively
implement jni wrapper of node.js
...
refer this link
https://github.com/paddybyers/anode/issues/15

Google App Engine, Java, and HTTP Performance

A friend and I are currently working on a turn-based game with chat with both desktop browser and Android clients, with Google App Engine as the server.
We're using the Java API for GAE and using HTTP for communication with the server. We've implemented simple chat functionality, and we're getting undesirable latencies 1-3 seconds from both the browser and Android clients while just posting simple one-word chat messages.
My friend thought it would be best to use XMPP instead of HTTP, but we want to use a Google Accounts cookie for authentication from the Android client, and according to the GAE documentation, XMPP clients cannot use a Google Accounts cookie and must use the user's password.
Does anyone have any suggestions as to where the latency might be coming from, how to troubleshoot it, and/or what to do about it?
Also, is anyone aware of any opensource implementations of chat (or something similar) on GAE done in Java? Can't seem to find any.
One way to analyze the situation would be to use Wireshark to look at the network traffic during the delays.
You don't say how your chat messages are getting from one JVM to the other. If you're using the datastore, maybe try memcache?
Also, startup time is often an issue; app engine starts and stops JVMs all the time, particularly for a low-traffic app. A way to diagnose this is to reload the page a bunch of times (send more messages) and see if it gets faster after a while. It should be pretty easy to tell the difference in the admin console logs.

Categories