adb_shell.transport.tcp_transport module

A class for creating a socket connection with the device and sending and receiving data.

class adb_shell.transport.tcp_transport.TcpTransport(host, port=5555)[source]

Bases: BaseTransport

TCP connection object.

Parameters:
  • host (str) – The address of the device; may be an IP address or a host name

  • port (int) – The device port to which we are connecting (default is 5555)

_connection

A socket connection to the device

Type:

socket.socket, None

_host

The address of the device; may be an IP address or a host name

Type:

str

_port

The device port to which we are connecting (default is 5555)

Type:

int

_abc_impl = <_abc._abc_data object>
bulk_read(numbytes, transport_timeout_s)[source]

Receive data from the socket.

Parameters:
  • numbytes (int) – The maximum amount of data to be received

  • transport_timeout_s (float, None) – When the timeout argument is omitted, select.select blocks until at least one file descriptor is ready. A time-out value of zero specifies a poll and never blocks.

Returns:

The received data

Return type:

bytes

Raises:

TcpTimeoutException – Reading timed out.

bulk_write(data, transport_timeout_s)[source]

Send data to the socket.

Parameters:
  • data (bytes) – The data to be sent

  • transport_timeout_s (float, None) – When the timeout argument is omitted, select.select blocks until at least one file descriptor is ready. A time-out value of zero specifies a poll and never blocks.

Returns:

The number of bytes sent

Return type:

int

Raises:

TcpTimeoutException – Sending data timed out. No data was sent.

close()[source]

Close the socket connection.

connect(transport_timeout_s)[source]

Create a socket connection to the device.

Parameters:

transport_timeout_s (float, None) – Set the timeout on the socket instance