AutobahnAndroid
Overview Get Started Tutorials Reference Downloads Get in touch

AutobahnAndroid is an open-source networking library for Java/Android created by the Autobahn project that implements

  • The WebSocket Protocol and
  • The WebSocket Application Messaging Protocol (WAMP)
for creating native mobile WebSocket/WAMP clients. Tweet


Features
  • supports WebSocket RFC6455, Draft Hybi-10+ and WAMP v1
  • works on Android 2.2+
  • very good standards conformance
  • high-performance asynchronous design
  • easy to use API
  • seamless integration in Android UI apps
  • no (really none) network activity on UI thread
  • Open-source (Apache 2 license)

You can use AutobahnAndroid to create native Android apps talking to WebSocket servers or any WAMP compatible server.

Here is a simple WebSocket echo client:

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());
               }
            }
         
Complete Tutorial:     WebSocket Echo Client

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:

WAMP RPC & PubSub Client

            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;
                                        }
                                     }
               );
            }
         
Complete Tutorials:   WAMP RPC Client   WAMP PubSub Client

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.