我建议你应该使用像PubNub这样的给定服务(参见演示)。
这样你就可以保存你的服务器开发,还有一个Android示例,你可以简单地在你的APP中使用它,如下所示:
dependencies {
....
compile 'com.pubnub:pubnub:3.7.4'
//'com.pubnub:pubnub-android-debug:3.7.+' For the debug version
}
和
import com.pubnub.api.*;
import org.json.*;
Pubnub pubnub = new Pubnub("demo", "demo");
try {
pubnub.subscribe("my_channel", new Callback() {
@Override
public void connectCallback(String channel, Object message) {
pubnub.publish("my_channel", "Hello from the PubNub Java SDK", new Callback() {});
}
@Override
public void disconnectCallback(String channel, Object message) {
System.out.println("SUBSCRIBE : DISCONNECT on channel:" + channel
+ " : " + message.getClass() + " : "
+ message.toString());
}
public void reconnectCallback(String channel, Object message) {
System.out.println("SUBSCRIBE : RECONNECT on channel:" + channel
+ " : " + message.getClass() + " : "
+ message.toString());
}
@Override
public void successCallback(String channel, Object message) {
System.out.println("SUBSCRIBE : " + channel + " : "
+ message.getClass() + " : " + message.toString());
}
@Override
public void errorCallback(String channel, PubnubError error) {
System.out.println("SUBSCRIBE : ERROR on channel " + channel
+ " : " + error.toString());
}
}
);
} catch (PubnubException e) {
System.out.println(e.toString());
}
如果您正在寻找Uber如何做到这一点的想法,请查看教程“PubNub联网汽车解决方案套件”"
所以我希望我能回答,Uber是如何做到这一点的,以及如何让它变得更好:-)