Data push in Android from a Java server - java

I am developing an Android application that connects to a Java server (with sockets). How I can do to make the server send data to clients when some data is changed on the server?

i would recommend using googles push services:
http://developer.android.com/google/gcm/index.html
that way you don't need a static connection to the server, but just fetch new data from the server if the client receives a push notification (or- if the information is not too big, you can add it as payload to the push notification).
alternatively if you want to support multiple platforms you could also take a look at services like urban airship:
http://urbanairship.com/

Related

How to make a server to send arduino sensors data to use it in my java application

I have an arduino device and i want to send the arduino sensors data to a server so i can fetch the data and store it in sqlite database and use it in my java application.
I already bought a domain name from goDaddy but I don’t know to do next, can you please help me?
You need a server, and you may be able to get one for free, but if you can't than you would need to rent a server from one of the many companies offering such service. You can get one from Amazon AWS, Google GCP, or smaller but not less reliable companies like Digital Ocean.
You need the minimum and least expensive configuration of a virtual machine which you will connect to using SSH text terminal. For instance you can get a Linux server and have your code run behind Apache webserver.
You can send data from Arduino to your server using simple GET strings over HTTP/S or utilize MQTT if you need the server to also send commands to the board.

Google Cloud Messaging and MySQL database

I want to use Google Cloud Messaging for my app for both upstream and downstream use, using xmpp. However I am wondering how I can select and input data to and from my MySQL database to be sent over the GCM network.
Can I use PHP with GCM or do I have to use Java or Python?
GCM is used for sending messages FROM server TO your android application. Also a GCM message can only carry a maximum of 4KB Only.
So in my opinion, send data to your MySQL db directly from the app (If you want to make this asynchronous, look into Android Sync Adapter); and for sending data from server to your application asynchronously, send a ping to your app using GCM (it can be any short message), so your app can undergo a normal http request-response procedure to get the data from MySQL.
For more information of Sync Adapters: http://developer.android.com/training/sync-adapters/index.html
And for a tutorial on a simple GCM using PHP: http://www.programming-techniques.com/2014/01/google-cloud-messaging-gcm-in-android.html
There are XMPP libraries for PHP. See https://code.google.com/p/xmpphp/ for example.
So, PHP is possible, however i would really like to hear what is a recommended approach, as im going to implement it too.

Global architecture presence user connected

I had before a project where i need to push data(websocket) to the client i used spring and atmosphere framework(an abstract of websocket in java). But finally i think actually websocket app in java are not enough good since i used nodejs&socket.io for an another project. It was so easy and a great experience to code an push data api.
So now i am thinking about an architecture and i want to share with you to know if its a good practices.
I have my server spring, client and nodejs/socket.io. I want to use nodejs just to store de socket and push event.
So imagine the server has to push data to specific users i will call a service in nodejs and he will push it.
So the nodejs API will just redirect requests to a user, nothing more.
Is that a good practice ?
Thanks for your idea
I would advice you decouple java application server and nodejs (socket server) and communicate using a middleware (messaging system..)
Let's say your java application is running on http://abc.com:1234 and socket.io on http://abc.com:5678. Then when the page is opened you can subscribe of the socket server.
Once you have some data to push, put it on middleware. SocketIO server will pick it up from there and pushes to all the browser client subscribed.

Create a basic network app

I have a little question about an android app with a function "remote" use via internet.
So I have these ideas:
Create a webservice using php on the server, and refresh the client app all x time like 4-5 sec
Or make a java server (so I don't know how I can do that)
I just want make a remote connected via user/password to the server and the other app connect to the server and refresh his status.
Do you know the best way for do that?
Thanks
The question is not very precise, but as far as I understand it, both your ideas implement the 'pull' concept, that is the client app checking the status of the server every now and then.
If you want the app to be instantly notified of the server status change, I would suggest push notifications with GCM (Google Clound Messaging). You can find some basic descriptions and examples at: http://developer.android.com/google/gcm/index.html
Sending a server-to-client notification is simple regardless of the platform you use server side. E.g. for PHP integration with GCM, check out this thread: GCM with PHP (Google Cloud Messaging)

Check File in the server is change or not

I am trying to make an app that connect to the server.
The app is used by some devices.
If one of the devices upload something to the server, I would like other devices receive the notification about the server has something new.
My question is, how to check the server is change or not? How often we must check the server?
I wonder how the Online Messaging work, because someone send something, we receive the message ASAP
Is the concept can be use with my app?
Sounds like you want to take advantage of Google Could Messaging or GCM for short.
http://developer.android.com/guide/google/gcm/index.html
This could be a lightweight message telling the Android application that there is new data to be fetched from the server (for instance, a movie uploaded by a friend), or it could be a message containing up to 4kb of payload data (so apps like instant messaging can consume the message directly).
GCM is the standard for how your apps "talk" to your servers. Either for a message in it's entirety or just a message to go check the server because it's been updated.

Categories

Resources