Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send real time data from java to android application

I need to send data from a java app to an android app in real time. The data is not large(integers within 0 and 9) but the number of transmissions is high, around 5 transmissions per second.

I wish to have a publisher subscriber model. Java app is going to push data to the android app instead of android app continuously pinging the java app for data.

Transmission has to be in real time and will happen over a LAN.

Tried with GCM but its not real time. Pubnub is another but not sure how realtime it will be.

How to proceed ?

like image 317
Soumya Avatar asked Jun 12 '14 05:06

Soumya


1 Answers

PubNub is as real-time as it gets... and it's super easy to make a Java server talk to Android device (in fact, PubNub has client SDKs for over 50 different platforms!).

This same code will run on both Android and plain Java:

import com.pubnub.api.*;
import org.json.*;

Pubnub pubnub = new Pubnub("demo", "demo");

Callback callback = new Callback() {
  public void successCallback(String channel, Object response) {
      Log.d("PUBNUB",response.toString());
  }
  public void errorCallback(String channel, PubnubError error) {
      Log.d("PUBNUB",error.toString());
  }
};

try {
  pubnub.subscribe("demo", callback);
    } catch (PubnubException e) {
  Log.d("PUBNUB",e.toString());
}

pubnub.publish("demo", "Hello World !!" , callback);

The complete walkthrough is available here:

http://www.pubnub.com/docs/java/javase/tutorial/data-push.html

If you have additional questions about it, feel free to contact [email protected], and they'll be happy to assist you further.

geremy

like image 191
Geremy Avatar answered Sep 30 '22 14:09

Geremy