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

# Client

> Asyncio TCP client that sends ISO 8583 requests and waits for their responses.

`iso8583sim.net.client`

## `ISO8583Client`

```python theme={null}
ISO8583Client(
    host: str,
    port: int,
    wire_format: WireFormat | None = None,
    framing: Framing | None = None,
    timeout: float = 10.0,
    ssl: ssl_module.SSLContext | bool | None = None,
    version: ISO8583Version = ISO8583Version.V1987,
)
```

Send requests to an ISO 8583 host over TCP.

Responses are matched to requests by STAN (field 11), so several requests can be in
flight on one connection at once.

**Example**

```python theme={null}
async with ISO8583Client("127.0.0.1", 8583) as client:
    response = await client.send(sample_message())
    print(response.fields[39])
```

**Parameters**

<ResponseField name="host" type="str" required>
  Host name or address
</ResponseField>

<ResponseField name="port" type="int" required>
  TCP port
</ResponseField>

<ResponseField name="wire_format" type="WireFormat | None" default="None">
  Byte layout of messages (defaults to ASCII with a binary bitmap)
</ResponseField>

<ResponseField name="framing" type="Framing | None" default="None">
  Length header and optional TPDU (defaults to a 2-byte binary header)
</ResponseField>

<ResponseField name="timeout" type="float" default="10.0">
  Seconds to wait for a response
</ResponseField>

<ResponseField name="ssl" type="ssl_module.SSLContext | bool | None" default="None">
  True or an SSLContext to connect over TLS
</ResponseField>

<ResponseField name="version" type="ISO8583Version" default="ISO8583Version.V1987">
  ISO 8583 version used to decode responses
</ResponseField>

### `connect()`

```python theme={null}
async def connect() -> None
```

Open the connection. send() also connects on demand.

### `close()`

```python theme={null}
async def close() -> None
```

Close the connection. Requests still waiting fail with ConnectionError.

### `send()`

```python theme={null}
async def send(message: ISO8583Message, timeout: float | None = None) -> ISO8583Message
```

Send a request and return the matching response.

**Parameters**

<ResponseField name="message" type="ISO8583Message" required>
  Request message. It must have a STAN (field 11).
</ResponseField>

<ResponseField name="timeout" type="float | None" default="None">
  Seconds to wait for the response (defaults to the client timeout)
</ResponseField>

<ResponseField name="Returns" type="ISO8583Message">
  The decoded response
</ResponseField>

**Raises**

* `TimeoutError`: No response arrived in time
* `ConnectionError`: The connection closed before the response arrived


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.