# TCP Usage

Send TCP traffic to remote devices from the User Console or API.

With **Remote Command**, you can use the Soracom API to send TCP data to a device that uses an IoT SIM.

> [!WARNING]
>
> Ensure your device is configured to accept incoming TCP data before using this feature.

## Programmatic Usage

### Soracom API

To access the Soracom API, first use the [**auth**](https://docs.soracom.io/en/api#!/Auth/auth) API to obtain an API Key and Token. Refer to the [**API Usage Guide**](https://docs.soracom.io/en/developers/soracom-api) for instructions on how to use the API Key and Token in API requests.

Then, use the [sendDownlinkTcp](https://docs.soracom.io/en/api#!/Sim/sendDownlinkTcp) API to send TCP data to a device that has an IoT SIM:

**Global**

```bash
curl -X POST \
  -H 'X-Soracom-API-Key: <MY-API-KEY>' \
  -H 'X-Soracom-Token: <MY-TOKEN>' \
  -H 'Content-Type: application/json' \
  -d '{
        "payload": "FFFFFF",
        "payloadEncoding": "hex",
        "port": 5005,
        "connectionOptions": {
          "type": "wait_for_pattern",
          "terminationPattern": "0A",
          "terminationPatternEncoding": "hex"
        }
      }' \
  https://g.api.soracom.io/v1/sims/<SIM_ID>/downlink/tcp

{"data":"EEEEEE0A","dataEncoding":"hex"}
```

**Japan**

```bash
curl -X POST \
  -H 'X-Soracom-API-Key: <MY-API-KEY>' \
  -H 'X-Soracom-Token: <MY-TOKEN>' \
  -H 'Content-Type: application/json' \
  -d '{
        "payload": "FFFFFF",
        "payloadEncoding": "hex",
        "port": 5005,
        "connectionOptions": {
          "type": "wait_for_pattern",
          "terminationPattern": "0A",
          "terminationPatternEncoding": "hex"
        }
      }' \
  https://jp.api.soracom.io/v1/sims/<SIM_ID>/downlink/tcp

{"data":"EEEEEE0A","dataEncoding":"hex"}
```

### Soracom CLI

To use the Soracom CLI, you must first configure it to authenticate with your account information, authorization key, or SAM user credentials.

Run the following command to send a TCP data to a device that has an IoT SIM:

**Global**

```bash
body='{
        "payload": "FFFFFF",
        "payloadEncoding": "hex",
        "port": 5005,
        "connectionOptions": {
          "type": "wait_for_pattern",
          "terminationPattern": "0A",
          "terminationPatternEncoding": "hex"
        }
      }'
soracom sims downlink-tcp --sim-id <SIM_ID> --body ${body} --coverage-type g

{"data":"EEEEEE0A","dataEncoding":"hex"}
```

**Japan**

```bash
body='{
        "payload": "FFFFFF",
        "payloadEncoding": "hex",
        "port": 5005,
        "connectionOptions": {
          "type": "wait_for_pattern",
          "terminationPattern": "0A",
          "terminationPatternEncoding": "hex"
        }
      }'
soracom sims downlink-tcp --sim-id <SIM_ID> --body ${body} --coverage-type jp

{"data":"EEEEEE0A","dataEncoding":"hex"}
```
