SAFS TCP Messenger Service for Android


 Author: Carl Nagle
  Since: FEB 24, 2012
Updated: FEB 27, 2012 Carl Nagle, org.safs.android.messenger.client info

Copyright SAS Institute, Inc.
http://www.sas.com
General Public License (GPL)
http://www.opensource.org/licenses/gpl-license.php

The SAFS TCP Messenger Service for Android is an Android application that provides general-purpose TCP messaging services between remote clients and installed Android applications that DO NOT have Android INTERNET permissions.

For example, Android test applications testing Android application that do not have INTERNET permissions are themselves not allowed to have INTERNET permissions.  By using the SAFS TCP Messenger Service the test application can communicate with a remote test controller, receive external commands via TCP sockets, and return test results or data to the remote controller.

The initial uses for this SAFS TCP Messenger Service are to provide for Robotium Remote Control and SAFS Android Remote Control using the SAFS Automation Framework.  However, the general-purpose nature of the SAFS TCP Messenger Service makes it suitable for other uses on Android independent of these test automation solutions.

Upon release, an independent SAFS TCP Messenger will be available from the SAFS Downloads Page.

The SAFS TCP Messenger will also be bundled as part of a future Robotium Remote Control download, and/or a future SAFS Android Support download.

SAFS TCP Messenger Service Assets

Remote TCP Client Development

Generally, developers wishing to create a remote TCP client simply have to implement a CommandListener interface listening to an instance of a MessengerRunner.

Developers provide their own message content and syntax to be transported over the predefined SocketProtocol.  This content will ultimately be received by the SAFS TCP Messenger and forwarded to the Android application.  So the Android application must be coded to understand the content, know how to parse it, and know what the remote client might be expecting in return.

The SAFS TCP Messenger doesn't care about the message syntax as long as the content conforms to being transported over the SocketProtocol.

Android Application Development

The Android application must will have the following Java library dependencies previously mentioned. These will reside in the Android project's /libs directory:

The Android application will generally launch the SAFS TCP Messenger during it's onCreate method to insure the Service is available when the application is launched.  The application will bind with the Service--usually with an instance of a MessengerRunner as shown below.

Then, if your CommandListener needs to respond to any incoming message it can do so with the methods already available from the MessengerRunner:

    messageRunner.sendReady();
    messageRunner.sendRunning();
    messageRunner.sendServiceResult(java.util.Properties);
    messageRunner.sendServiceResult(int,java.lang.String);
    messageRunner.sendMessage(java.lang.String);
    messageRunner.sendException(java.lang.String);
    messageRunner.sendDebug(java.lang.String);
    messageRunner.sendShutdown();

The Android SDK provides examples of implementing Android Messaging with Android services.  Our implementations for both Robotium Remote Control and SAFS Remote Control also serve as real-world examples of using the SAFS TCP Messenger Service specifically.

The Android application will ultimately be communicating with the SAFS TCP Messenger using the Inter-Process Communication (IPC) protocols provided by the Android OS.