public class DroidSocketProtocol extends SocketProtocol
SocketProtocol
, before connect to serverSocketProtocol
,
AbstractProtocolRunner
Modifier and Type | Field and Description |
---|---|
(package private) java.lang.String[] |
tcpfowardParams |
(package private) static AndroidTools |
tools |
_debugEnabled, controllerPort, controllerRunner, debugprefix, DEFAULT_CONTROLLER_PORT, DEFAULT_REMOTE_PORT, DEFAULT_SERVER, ENV_KEY_REMOTE_PORT, EOM, MAX_SERVER_PORT, MSG_PROTOCOL_VERSION_QUERY, NEXT_SERVER_PORT_PACE, remoteHostname, remotePort, STATUS_SHUTDOWN_CONTROLLER, STATUS_SHUTDOWN_NORMAL, STATUS_SHUTDOWN_REMOTE_CLIENT, STATUS_SHUTDOWN_REMOTE_SERVICE, STATUS_STRINGS, TAG
Constructor and Description |
---|
DroidSocketProtocol() |
DroidSocketProtocol(NamedListener listener) |
Modifier and Type | Method and Description |
---|---|
void |
adjustControllerPort()
Choose an available port (not occupied by other ServerSocket or DatagramSocket) for controller port.
After calling this, you should NOT call SocketProtocol.setControllerPort(int) unless you know you are settingan available port for controller port. This method should be called after calling setPortForwarding(boolean) |
protected void |
bindToRemoteServer()
Override the method in super class.
If we have forwarded the tcp port from SocketProtocol.controllerPort to SocketProtocol.remotePort . |
boolean |
forwardPort(int localPCPort,
int remoteDevicePort)
Use adb to forward local machine's port to a device/emulator's port
|
boolean |
getPortForwarding()
get the value of
portForwarding |
static void |
main(java.lang.String[] args)
This method will prove that we can create a connection SUCCESSFULLY with a 'serverPort' where
no SocketServer is running, the precondition is that we use adb to forward that 'serverPort' to
a port on device/emulator (even there is NO SocketServer running on that port on device/emulator)
This prove that the connection is probably not a real one if we used 'adb port forwarding'.
|
void |
setPortForwarding(boolean portForwarding)
set the value for field
portForwarding If the 'port forwarding' is set to true, remember to call adjustControllerPort() to choose an available port for 'controller'. |
acceptProtocolVersion, addListener, closeProtocolRunners, connectProtocolRunners, debug, getClientConnectTimeout, getConnectedProtocol, getControllerPort, getEOM, getKeepAlive, getNextPort, getRemoteHostname, getRemotePort, getShutdownCauseDescription, isConnected, isLocalMode, removeListener, sendResponse, setClientConnectTimeout, setControllerPort, setEOM, setKeepAlive, setLocalMode, setRemoteHostname, setRemotePort, waitForInput
java.lang.String[] tcpfowardParams
static AndroidTools tools
public DroidSocketProtocol()
public DroidSocketProtocol(NamedListener listener)
protected void bindToRemoteServer() throws java.io.IOException
SocketProtocol.controllerPort
to SocketProtocol.remotePort
.
we will use the SocketProtocol.controllerPort
to create connection.super#bindToRemoteServer()
, which use SocketProtocol.remotePort
to create connection.
Attention:
If port forwarding is true, adb will make a port forward from SocketProtocol.controllerPort
to SocketProtocol.remotePort
BUT, adb will NOT check if there is a ServerSocket running on the SocketProtocol.remotePort
After forwarding, the Socket SocketProtocol.controllerRunner
can always be created successfully.
So this socket connection is not reliable!!! See main(String[])
.
If verification fail, retry connection IS NEEDED.
bindToRemoteServer
in class SocketProtocol
java.io.IOException
#retryConnectionAfterVerificationFail()
public void setPortForwarding(boolean portForwarding)
portForwarding
adjustControllerPort()
portForwarding
- adjustControllerPort()
public boolean getPortForwarding()
portForwarding
public boolean forwardPort(int localPCPort, int remoteDevicePort)
localPCPort
- int, port number of local machineremoteDevicePort
- int, port number of device/emulatorpublic void adjustControllerPort()
SocketProtocol.setControllerPort(int)
unless you know you are settingsetPortForwarding(boolean)
public static void main(java.lang.String[] args)
args
- Copyright © SAS Institute. All Rights Reserved.