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

# Connecting to TCP Server

> This guide explains how to connect to the Benzinga TCP streaming server and start receiving real-time data.

## Server Endpoint

| Parameter | Value |
| - | - |
| **Host** | `tcp-v1.benzinga.io` |
| **Port** | `11337` |
| **Protocol** | TCP |
| **TLS** | Optional (disabled by default) |

## Authentication

Connect using your username and API key:

```bash theme={null}
bztcp -v -user YOUR_USERNAME -key YOUR_API_KEY
```

### Command Line Options

| Option | Description |
| - | - |
| `-user` | Your Benzinga TCP username |
| `-key` | Your API access key |
| `-v` | Enable verbose output |

## Connection Flow

```mermaid theme={null}
sequenceDiagram
    participant Client
    participant Server as tcp-v1.benzinga.io:11337
    
    Client->>Server: Connect with credentials
    Server->>Client: Authentication response
    Note over Client,Server: Connection established
    loop Streaming
        Server->>Client: JSON message
        Server->>Client: JSON message
        Server->>Client: ...
    end
```

## Connection States

Once connected, you'll see initialization messages:

```
Benzinga TCP Client initializing.
Connecting to 'tcp-v1.benzinga.io:11337' as user 'YOUR_USERNAME' (w/TLS: false)
Connected. Waiting for events.
```

After the connection is established, JSON messages begin streaming automatically.

## TLS Configuration

By default, connections are made without TLS. To enable TLS encryption, use the appropriate flag provided by your client library.

## Connection Best Practices

> [!NOTE]
>
> Keep your connection alive to receive continuous updates. Implement reconnection logic to handle network interruptions gracefully.

### Recommended Practices

1. **Implement Reconnection Logic**: Network interruptions can occur; implement exponential backoff for reconnection attempts
2. **Handle Disconnections**: Monitor connection state and reconnect when needed
3. **Buffer Messages**: Process messages asynchronously to avoid blocking the receive loop
4. **Log Connection Events**: Track connection status for debugging and monitoring

## Example Connection

> [tab] Go
>
> ```go theme={null}
> conn, err := bztcp.Dial("tcp-v1.benzinga.io:11337", "USERNAME", "API_KEY")
> if err != nil {
>     log.Fatal(err)
> }
> ```

> [tab] Python
>
> ```python theme={null}
> from bztcp.client import Client
>
> client = Client(username='USERNAME', key='API_KEY')
> ```

## Next Steps

* [Message Format](https://benzinga.mintlify.site/tcp-reference/message-format.md) - Learn about message structure
* [Python Client](https://benzinga.mintlify.site/tcp-reference/python-client.md) - Full Python library documentation
* [Go Client](https://benzinga.mintlify.site/tcp-reference/go-client.md) - Full Go library documentation
