org.safs.android
Class SocketServer

java.lang.Object
  extended by org.safs.sockets.AbstractProtocolRunner
      extended by org.safs.android.SocketServer
All Implemented Interfaces:
java.lang.Runnable, ConnectionListener, DebugListener, NamedListener

public class SocketServer
extends AbstractProtocolRunner

This class is the "local" controller side implementation of an AbstractSocketRunner. The class provides the SocketProtocol implementation needed by the DJavaHook to communicate with the SAFS Messenger Service on an Android device or emulator.

When using the Android Emulator, the emulator must be configured to "see" Socket requests on its local port 2410 coming from the controller on port 2411. Do this with the adb forwarding command to the running emulator as follows:

adb forward tcp:2411 tcp:2410

There is an initial handshake or verification that occurs between this remote controller server and the on-device Service to confirm the device port owner is a SAFS TCP Messenger Service.

See Also:
DJavaHook, MessengerService, DroidEngine

Field Summary
 
Fields inherited from class org.safs.sockets.AbstractProtocolRunner
_debugEnabled, protocolserver, runnerlisteners
 
Constructor Summary
SocketServer()
          Default no-op constructor setting SocketServer to use all defaults.
SocketServer(SocketServerListener listener)
          Constructor setting SocketServer to use all defaults while registering a SocketServerListener.
 
Method Summary
 void processProtocolMessage(java.lang.String message)
          Routine called by the asynchronous run loop when a message has been received from the remote SocketProtocol.
 boolean sendDispatch(java.util.Properties trd)
          Send the remote client a DISPATCHPROPS message containing a Serialized Properties object containing all the testRecordData and other data needed for the execution of the Dispatch.
 boolean sendDispatch(java.lang.String filepath)
          Send the remote client a DISPATCHFILE message with the filepath to a file suitable for Properties loading.
 boolean sendMessage(java.lang.String message)
          Send the remote client and arbitrary MESSAGE content.
 boolean sendShutdown()
          Send the remote client a shutdown command
 
Methods inherited from class org.safs.sockets.AbstractProtocolRunner
addListener, debug, getListenerName, onReceiveConnection, onReceiveDebug, onReceiveLocalShutdown, onReceiveRemoteShutdown, removeListener, run, sendProtocolMessage, setListenerName, shutdownThread
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SocketServer

public SocketServer()
Default no-op constructor setting SocketServer to use all defaults. The user should change any desired remote hostname/port settings and add any DebugListeners, ConnectionListeners, and SocketServerListeners prior to starting the Runnable thread.


SocketServer

public SocketServer(SocketServerListener listener)
Constructor setting SocketServer to use all defaults while registering a SocketServerListener. The user should change any desired remote hostname/port settings prior to starting the Runnable thread.

Parameters:
listener - SocketServerListener to register with the new instance.
Method Detail

sendDispatch

public boolean sendDispatch(java.util.Properties trd)
Send the remote client a DISPATCHPROPS message containing a Serialized Properties object containing all the testRecordData and other data needed for the execution of the Dispatch.

"dispatchprops:char[]data"

Parameters:
Properties - trd to serialize with properties.store
Returns:
true if the message was sent successfully.
See Also:
Properties.store(OutputStream, String), SocketServer.notifyDispatchProps(char[]), MessengerService.onReceiveDispatchProps(char[]), DroidEngine.onRemoteDispatchProps(java.util.Properties)

sendDispatch

public boolean sendDispatch(java.lang.String filepath)
Send the remote client a DISPATCHFILE message with the filepath to a file suitable for Properties loading.

"dispatchfile:filpath"

The remote client is expected to receive the Dispatch and forward the filepath info to the actual remote engine.

Parameters:
filepath -
Returns:
true if the message was successfully sent.
See Also:
SocketServer.notifyDispatchFile(String), MessengerService.onReceiveDispatchFile(String), DroidEngine.onRemoteDispatchFile(String)

sendMessage

public boolean sendMessage(java.lang.String message)
Send the remote client and arbitrary MESSAGE content.

The remote client is expected to forward the message to the remote engine with the "message:" prefix stripped off. These messages are NOT part of the standard SAFS protocol and it is up to the local and remote engines to know what to do with them.

Parameters:
message -
Returns:
true if the message was successfully sent.
See Also:
SocketServer.notifyMessage(String), MessengerService.onReceiveMessage(String), DroidEngine.onRemoteMessage(String)

sendShutdown

public boolean sendShutdown()
Send the remote client a shutdown command

Returns:
response from sendClient. false if sendClient throws an InvalidObjectException.
See Also:
SocketServer.notifyMessage(String), MessengerService.onReceiveRemoteShutdown(int), DroidEngine.onRemoteShutdown()

processProtocolMessage

public void processProtocolMessage(java.lang.String message)
Routine called by the asynchronous run loop when a message has been received from the remote SocketProtocol. This routine is used to parse and then route the message to the appropriate SocketServerListener callback functions.

Specified by:
processProtocolMessage in class AbstractProtocolRunner
See Also:
SocketServerListener