AutobahnAndroid is an open-source networking library for Java/Android created by the Autobahn project that implements
for creating native mobile WebSocket/WAMP clients. TweetYou can use AutobahnAndroid to create native Android apps talking to WebSocket servers or any WAMP compatible server.
Here is a simple WebSocket echo client:
private final WebSocketConnection mConnection = new WebSocketConnection();
private void start() {
final String wsuri = "ws://localhost:9000";
try {
mConnection.connect(wsuri, new WebSocketHandler() {
@Override
public void onOpen() {
Log.d(TAG, "Status: Connected to " + wsuri);
mConnection.sendTextMessage("Hello, world!");
}
@Override
public void onTextMessage(String payload) {
Log.d(TAG, "Got echo: " + payload);
}
@Override
public void onClose(int code, String reason) {
Log.d(TAG, "Connection lost.");
}
});
} catch (WebSocketException e) {
Log.d(TAG, e.toString());
}
}
WAMP allows to develop real-time enabled apps based on asynchronous RPC and PubSub messaging patterns.
Here is a simple WAMP client calling a RPC endpoint and subscribing to a PubSub topic:
private final AutobahnConnection mConnection = new AutobahnConnection();
private void start() {
final String wsuri = "ws://localhost:9000";
mConnection.connect(wsuri, new Autobahn.SessionHandler() {
@Override
public void onOpen() {
testRpc();
testPubSub();
}
@Override
public void onClose(int code, String reason) {
}
});
}
private void testRpc() {
mConnection.call("http://example.com/calc#add",
Integer.class,
new Autobahn.CallHandler() {
@Override
public void onResult(Object result) {
int res = (Integer) result;
Log.d(TAG, "calc:add result = " + res);
}
@Override
public void onError(String error, String info) {
}
},
23, 55
);
}
private static class MyEvent1 {
public int num;
public String name;
public boolean flag;
public Date created;
public double rand;
}
private void testPubSub() {
mConnection.subscribe("http://example.com/events#myevent1",
MyEvent1.class,
new Autobahn.EventHandler() {
@Override
public void onEvent(String topic, Object event) {
MyEvent1 evt = (MyEvent1) event;
}
}
);
}
You can use any Java basic type or POJO with RPC and PubSub and have i.e. PubSub event payloads automatically mapped to your POJOs.
If you like, get started, check out the tutorials and - for complete information - the API reference.
Autobahn WebSocket technology is brought to you by
Tavendo, WAMP and "Autobahn WebSocket" are trademarks of Tavendo GmbH. All other trademarks are those of their respective entities.
Copyright © 2011-2013, Tavendo GmbH. Content licensed under Creative Commons CC-BY-SA and code licensed under Apache 2.0.