> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/zwc456baby/ScrcpyForAndroid/llms.txt
> Use this file to discover all available pages before exploring further.

# Connection Setup

> Learn how to connect Scrcpy for Android to remote devices over local and public networks

## Overview

Scrcpy for Android allows you to mirror and control another Android device from your phone. This guide covers the different connection methods available.

## Prerequisites

Before connecting, ensure:

* Wireless debugging is enabled on the target device
* ADB is configured on the target device
* Both devices are on the same network (for local connections)

<Tip>
  Run `adb tcpip 5555` on your target device to reset the ADB port to the default port.
</Tip>

## Connection Methods

### Local Network Connection

The most common way to connect is over a local Wi-Fi network:

1. Find the IP address of the target device (usually in Settings > About Phone > Status)
2. Enter the IP address in the "Remote Device IP address" field
3. Click "Start" to initiate the connection

<CodeGroup>
  ```text Example IPv4 theme={null}
  192.168.0.73
  ```

  ```text Example with Custom Port theme={null}
  192.168.0.73:5555
  ```
</CodeGroup>

### Public Network Connection

For connections over the internet, you need to specify the public IP and port:

<Warning>
  Ensure port forwarding is configured on your router to forward the ADB port (default: 5555) to your target device.
</Warning>

**Required Ports:**

* **ADB Port**: 5555 (default, can be customized)
* **Local Forward Port**: 7008 (used internally for video/audio streaming)
* **Server Socket Port**: 7007 (used for communication)

### IPv6 Support

Scrcpy for Android supports IPv6 addresses. When using IPv6:

```text IPv6 Format theme={null}
[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:5555
```

<Note>
  IPv6 addresses should be enclosed in square brackets when specifying a port.
</Note>

## Connection History

The app automatically saves your connection history for quick access:

* Up to **30 devices** are stored in history
* Most recent connections appear first
* Tap the history icon next to the IP field to view saved addresses
* History is preserved between app sessions

<Info>
  Connection history is not saved when using headless mode.
</Info>

## ADB Connection Process

When you initiate a connection, the following steps occur:

1. **ADB Connect**: App executes `adb connect <ip>:<port>`
2. **Server Upload**: Copies `scrcpy-server.jar` to `/data/local/tmp/` on target device
3. **Port Forward**: Sets up local port forwarding: `tcp:7008` → `tcp:7007`
4. **Server Start**: Launches the scrcpy server with configured resolution and bitrate
5. **Socket Connection**: Establishes TCP connection to `127.0.0.1:7008`

## Connection Timeout

The app implements intelligent timeout handling:

* **Initial connection attempts**: 50 attempts with 100ms intervals (5 seconds total)
* **Socket connection timeout**: 5000ms (5 seconds)
* **Resolution handshake**: Up to 1 second to receive device resolution
* **Overall timeout**: If connection isn't established, you'll see "Connection Timed out 2"

## Reconnection

If the connection drops:

* The app prompts you to retry the connection
* Previous settings (resolution, bitrate) are preserved
* After 3 failed connection attempts, the ADB server automatically restarts

<Tip>
  If you're experiencing repeated connection failures, try manually disconnecting and reconnecting in ADB, or restart wireless debugging on the target device.
</Tip>

## Testing Connection

To verify your connection setup:

1. Use the local loopback address `127.0.0.1` to test the app functionality
2. Check the connection history dropdown - it should show at least the loopback address
3. Monitor the connection status message - successful connections show the remote screen within seconds

## Next Steps

<CardGroup cols={2}>
  <Card title="Configuration" icon="sliders" href="/guides/configuration">
    Customize resolution, bitrate, and other settings
  </Card>

  <Card title="Troubleshooting" icon="wrench" href="/guides/troubleshooting">
    Solve common connection issues
  </Card>
</CardGroup>
