Help between communication between clients WEBSERVICE REST - JSON - JAVA

1

I'm developing an Android application where devices can communicate with each other through messaging (instant messaging).

My application is already connecting to the Web Service (I developed it using NetBeans) and the Web service connecting to the database (MySQL).

I can already carry out user registration through the application, sending the information to the Web service and Web service by registering in the database.

My question is, how can I get my application to send a message to another user, and the user receives the message instantly.

Getting the message to arrive on the Web service is apparently not difficult, with the information also for which user.

What I can not think of is how the customer (Android application) will understand that a message arrived for him. How the Web service will send the message to the specified user.

I use JSON to exchange information.

    
asked by anonymous 22.02.2016 / 14:36

1 answer

1

I believe that developing an efficient solution to send messages from the server to devices, in addition to being particularly complex, requires a structure that conventional http does not contemplate. This is definitely not the path you need to follow, unless you have some advanced structure like Amazon AWS and lots of experience.

The makers of mobile devices know of this difficulty and have created solutions to solve this issue without leaving any developer crazy. On android we have GCM (Google Cloud Message) , which sends messages up to 2kb to the device or devices specified.

There are many steps to demonstrate here, but the logic is as follows.

  • Every device android by default when connecting to the internet has a unique signature registered on google servers.
  • When your app registers to your server you register the device signature
  • In possession of the signature your server creates the message (with a maximum of 2kb) and sends it to Google GCM servers
  • GCM servers have direct access to all connected devices. They therefore send the message to the device.
  • The device processes the message that may be complete, or only a connection request to download more complex information.
  • If the need arises, the device connects back to your server to complete the download by for example.
  • As you can see, there are some necessary steps. Google offers all documentation for you , but unfortunately I did not find it in Portuguese.

    Of course there are other alternatives. Some paid services, such as parse.com solve all server logistics, but there is a burden on it. There are also some open source solutions that aim to provide a server structure already suited to mobile needs. One project that may have a promising future is the baasbox , but I do not know how it behaves in the production environment.

    Anyway, I hope I have helped.

        
    25.02.2016 / 05:31