There are several ways to implement a communication application. However, I will make some considerations.
Real-time?
No APP is exactly in real time. Anyone who uses WhatsApp, Google Hangouts or Facebook Messenger knows that the message often delays.
What you probably want is something that sends messages as early as possible.
Simple architecture
Sending the message
You basically need your application to send the message through an HTTP request. This is simple and just look at documentation .
Example:
final TextView mTextView = (TextView) findViewById(R.id.text);
...
// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(this);
String url ="http://www.google.com";
// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// Display the first 500 characters of the response string.
mTextView.setText("Response is: "+ response.substring(0,500));
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
mTextView.setText("That didn't work!");
}
});
// Add the request to the RequestQueue.
queue.add(stringRequest);
Redirecting the message
On the server side, you need a REST application that receives the HTTP request with the message. It would be nice to lock it into a database for history logging and other features.
The technologies used here can be:
- Servlets, JAX-RS, or Spring Boot to create web services
- JDBC, JDBC Template, or JPA for bank access
When you receive the message, your application must in turn make a request to an API such as Google Cloud Messaging to make the push of the message to the devices that are registered to receive it.
An example request would be:
https://gcm-http.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
"to": "/topics/foo-bar",
"data": {
"message": "This is a GCM Topic Message!",
}
}
Once this is done, Google's servers will notify the devices about the message.
To request this API you can use the Apache Http Client library.
Receiving the message
Finally, the messages would be received in the target device (s) in the following method:
@Override
public void onMessageReceived(String from, Bundle data) {
String message = data.getString("message");
Log.d(TAG, "From: " + from);
Log.d(TAG, "Message: " + message);
// Handle received message here.
}
Of course, it is necessary that the devices that will receive the messages have the application and that this application registers to receive the messages. Example:
private void subscribeTopics(String token) throws IOException {
GcmPubSub pubSub = GcmPubSub.getInstance(this);
for (String topic : TOPICS) {
pubSub.subscribe(token, "/topics/" + topic, null);
}
}
XMPP
This is a protocol that has implementations in Java, but this will not solve most of your problems, such as push to distribute messages to clients.
See this link for some implementations that you can use on the server side.
However, as I said, you still have to implement the entire application and distribution of messages.
Considerations
This is an example at a very high level. This is not an easy task.
I suggest that you create specific questions about each point you have questions and avoid asking so broadly about technology. Probably no one will do the whole job and post a step-by-step here.