Reverse port forwarding API#
Static methods of AltReversePortForwarding that run adb reverse for you, so an app on an Android device connected by USB can reach AltTester® Server on your machine. Call them before you create the driver and after you stop it. For when and why to use reverse port forwarding, see Reverse port forwarding.
Each command shows its signature and an example in every language; pick a language in any tab and the others switch with it.
Commands on this page#
Command |
What it does |
|---|---|
Forwards a port on the Android device to a port on this machine, by running |
|
Removes the forwarding of one device port, by running |
|
Removes every reverse port forwarding, by running |
AltReversePortForwarding#
Python and Robot Framework run adb from your PATH. C# and Java use adbPath when you give it; otherwise $ANDROID_SDK_ROOT/platform-tools/adb, and if ANDROID_SDK_ROOT isn’t set, adb from your PATH.
ReversePortForwardingAndroid#
Forwards a port on the Android device to a port on this machine, by running adb [-s deviceId] reverse tcp:remotePort tcp:localPort.
string ReversePortForwardingAndroid(
int remotePort = 13000,
int localPort = 13000,
string deviceId = "",
string adbPath = "")
Example
// Before connecting: let the app on the device reach AltTester® Server on this machine.
AltReversePortForwarding.ReversePortForwardingAndroid();
altDriver = new AltDriver();
void reversePortForwardingAndroid()
void reversePortForwardingAndroid(int localPort)
void reversePortForwardingAndroid(int localPort, int remotePort)
void reversePortForwardingAndroid(
int localPort,
int remotePort,
String deviceId)
void reversePortForwardingAndroid(
int remotePort,
int localPort,
String deviceId,
String adbPath)
Example
// Before connecting: let the app on the device reach AltTester® Server on this machine.
AltReversePortForwarding.reversePortForwardingAndroid();
altDriver = new AltDriver();
AltReversePortForwarding.reverse_port_forwarding_android(
device_port=13000,
local_port=13000,
device_Id='')
Example
from alttester import AltDriver, AltReversePortForwarding
# Before connecting: let the app on the device reach AltTester® Server on this machine.
AltReversePortForwarding.reverse_port_forwarding_android()
alt_driver = AltDriver()
Reverse Port Forwarding Android device_port=13000 local_port=13000 device_id=''
Example
# Before connecting: let the app on the device reach AltTester® Server on this machine.
Reverse Port Forwarding Android
Initialize AltDriver
Parameters
Name |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
The port on the device, the one the app connects to. |
|
|
|
The port on this machine, the one AltTester® Server listens on. |
|
|
|
The device’s serial number, as |
|
|
|
The |
Returns
string (C#), nothing (Java, Python, Robot): In C#, what adb wrote to its error output, or Ok when it wrote nothing.
Note
In Java, the overloads with one, two or three arguments pass their first port on as the device port, whatever its name: reversePortForwardingAndroid(13001) forwards device port 13001 to local port 13000. The four-argument overload takes remotePort first, as its names say.
If the app still can’t connect right after this call, adb may not have finished setting up the forwarding: wait a moment before creating the driver. Java already waits one second.
See also: RemoveReversePortForwardingAndroid · RemoveAllReversePortForwardingsAndroid
RemoveReversePortForwardingAndroid#
Removes the forwarding of one device port, by running adb [-s deviceId] reverse --remove tcp:remotePort.
void RemoveReversePortForwardingAndroid(
int remotePort = 13000,
string deviceId = "",
string adbPath = "")
Example
// After the tests: disconnect, then remove the forwarding.
altDriver.Stop();
AltReversePortForwarding.RemoveReversePortForwardingAndroid();
void removeReversePortForwardingAndroid()
void removeReversePortForwardingAndroid(int localPort)
void removeReversePortForwardingAndroid(
int localPort,
String deviceId)
void removeReversePortForwardingAndroid(
int remotePort,
String deviceId,
String adbPath)
Example
// After the tests: disconnect, then remove the forwarding.
altDriver.stop();
AltReversePortForwarding.removeReversePortForwardingAndroid();
AltReversePortForwarding.remove_reverse_port_forwarding_android(
device_port=13000,
device_Id='')
Example
# After the tests: disconnect, then remove the forwarding.
alt_driver.stop()
AltReversePortForwarding.remove_reverse_port_forwarding_android()
Remove Reverse Port Forwarding Android device_port=13000 device_id=''
Example
# After the tests: disconnect, then remove the forwarding.
Stop AltDriver
Remove Reverse Port Forwarding Android
Parameters
Name |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
The port on the device, the one the app connects to. |
|
|
|
The device’s serial number, as |
|
|
|
The |
Returns
Nothing.
Note
In Java, the port is the device port in every overload, although the shorter overloads call it localPort.
See also: ReversePortForwardingAndroid · RemoveAllReversePortForwardingsAndroid
RemoveAllReversePortForwardingsAndroid#
Removes every reverse port forwarding, by running adb reverse --remove-all.
void RemoveAllReversePortForwardingsAndroid(string adbPath = "")
Example
// After the tests: disconnect, then remove every reverse port forwarding.
altDriver.Stop();
AltReversePortForwarding.RemoveAllReversePortForwardingsAndroid();
void removeAllReversePortForwardingsAndroid()
void removeAllReversePortForwardingsAndroid(String adbPath)
Example
// After the tests: disconnect, then remove every reverse port forwarding.
altDriver.stop();
AltReversePortForwarding.removeAllReversePortForwardingsAndroid();
AltReversePortForwarding.remove_all_reverse_port_forwardings_android()
Example
# After the tests: disconnect, then remove every reverse port forwarding.
alt_driver.stop()
AltReversePortForwarding.remove_all_reverse_port_forwardings_android()
Remove All Reverse Port Forwardings Android
Example
# After the tests: disconnect, then remove every reverse port forwarding.
Stop AltDriver
Remove All Reverse Port Forwardings Android
Parameters
Name |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
The |
Returns
Nothing.
See also: ReversePortForwardingAndroid · RemoveReversePortForwardingAndroid