# visionai::StreamSender Class Reference

# visionai::StreamSender

`#include <streams.h>`

`https://docs.cloud.google.com/vision-ai/docs/reference/cpp/class/visionai/stream-sender#classvisionai_1_1_stream_sender` is the client through which users send `Packet`s to a stream.

## Summary

Each instance of the `https://docs.cloud.google.com/vision-ai/docs/reference/cpp/class/visionai/stream-sender#classvisionai_1_1_stream_sender` represents a single connection to a specific stream. Once created, the user may repeatedly call `Send` with new `Packet`s that they want to send to the stream.

Example - Repeatedly sending `Packet`s to a specific stream.


```c++
// First populate the options.
StreamSender::Options options;
options.service_connection_options = ...;
options.stream_id = "my-stream";

// Create an instance of the `StreamSender`.
auto stream_sender_statusor = StreamSender::Create(options);
if (!stream_sender.ok()) {
// An error occurred during the setup of the sender.
// You can fix the problem and try again.
}
auto stream_sender = std::move(*stream_sender_statusor);

// Now you can repeatedly send Packets.
while (true) {
  // Get a new packet from some function or generation mechanism.
  Packet p = SomeFunctionThatGetsNewPacketsToSend();

  auto status = stream_sender->Send(std::move(p));
  if (!status.ok()) {
    // An error occurred.
    // To retry, you must create a new instance of the sender.
  }
}

// When there are no more packets to send, remember to destroy the sender.
stream_sender->reset();
```

<br />

| ### Constructors and Destructors ||
|---|---|
| `https://docs.cloud.google.com/vision-ai/docs/reference/cpp/class/visionai/stream-sender#classvisionai_1_1_stream_sender_1a254f0297832ac131e5bcfec173e91603()` ||
| `https://docs.cloud.google.com/vision-ai/docs/reference/cpp/class/visionai/stream-sender#classvisionai_1_1_stream_sender_1aa6b70931accea46ea34200e32057a323(const https://docs.cloud.google.com/vision-ai/docs/reference/cpp/class/visionai/stream-sender#classvisionai_1_1_stream_sender &)` ||
| `https://docs.cloud.google.com/vision-ai/docs/reference/cpp/class/visionai/stream-sender#classvisionai_1_1_stream_sender_1a06d3fcc5169cf13a5e0c7dcdf3b7b751()` ||

| ### Public static functions ||
|---|---|
| `https://docs.cloud.google.com/vision-ai/docs/reference/cpp/class/visionai/stream-sender#classvisionai_1_1_stream_sender_1a1238dd0ec030cf9567ded4ed75ed6b91(const https://docs.cloud.google.com/vision-ai/docs/reference/cpp/struct/visionai/stream-sender/options#structvisionai_1_1_stream_sender_1_1_options &)` | `absl::StatusOr< std::unique_ptr< https://docs.cloud.google.com/vision-ai/docs/reference/cpp/class/visionai/stream-sender#classvisionai_1_1_stream_sender > >` Create a readily usable instance of a `https://docs.cloud.google.com/vision-ai/docs/reference/cpp/class/visionai/stream-sender#classvisionai_1_1_stream_sender`. |

| ### Public functions ||
|---|---|
| `https://docs.cloud.google.com/vision-ai/docs/reference/cpp/class/visionai/stream-sender#classvisionai_1_1_stream_sender_1a0abeda6df6bc32c98cf12711c4a67e38(Packet packet)` | `absl::Status` Send the given `packet` to a stream. |
| `https://docs.cloud.google.com/vision-ai/docs/reference/cpp/class/visionai/stream-sender#classvisionai_1_1_stream_sender_1a6a59498cb71cd412fb2e933a769744a2(Packet packet, absl::Duration timeout)` | `absl::Status` Send the given `packet` to a stream with a `timeout`. |
| `https://docs.cloud.google.com/vision-ai/docs/reference/cpp/class/visionai/stream-sender#classvisionai_1_1_stream_sender_1ac4495c65a38418a796f96b1d5eb37ad3(const https://docs.cloud.google.com/vision-ai/docs/reference/cpp/class/visionai/stream-sender#classvisionai_1_1_stream_sender &)=delete` | `https://docs.cloud.google.com/vision-ai/docs/reference/cpp/class/visionai/stream-sender#classvisionai_1_1_stream_sender &` |

| ### Structs ||
|---|---|
| [visionai::StreamSender::Options](https://docs.cloud.google.com/vision-ai/docs/reference/cpp/struct/visionai/stream-sender/options) | [Options](https://docs.cloud.google.com/vision-ai/docs/reference/cpp/struct/visionai/stream-sender/options#structvisionai_1_1_stream_sender_1_1_options) to configure the `https://docs.cloud.google.com/vision-ai/docs/reference/cpp/class/visionai/stream-sender#classvisionai_1_1_stream_sender`. |

## Public static functions

### Create

```c++
absl::StatusOr< std::unique_ptr< StreamSender > > Create(
  const Options &
)
```
Create a readily usable instance of a `https://docs.cloud.google.com/vision-ai/docs/reference/cpp/class/visionai/stream-sender#classvisionai_1_1_stream_sender`.

## Public functions

### Send

```c++
absl::Status Send(
  Packet packet
)
```
Send the given `packet` to a stream.

Returns OK on success. Otherwise, returns an error status.

To retry on a case of failure, you must create a new instance of the `https://docs.cloud.google.com/vision-ai/docs/reference/cpp/class/visionai/stream-sender#classvisionai_1_1_stream_sender` and `Send` through that.

The first overload blocks until the status of the `Send` is known. The second overload blocks up to `timeout` before returning CANCELLED.

### Send

```c++
absl::Status Send(
  Packet packet,
  absl::Duration timeout
)
```
Send the given `packet` to a stream with a `timeout`.

Returns OK on success. Otherwise, returns an error status.

To retry on a case of failure, you must create a new instance of the `https://docs.cloud.google.com/vision-ai/docs/reference/cpp/class/visionai/stream-sender#classvisionai_1_1_stream_sender` and `Send` through that.

The first overload blocks until the status of the `Send` is known. The second overload blocks up to `timeout` before returning CANCELLED.

### StreamSender

```c++
 StreamSender()=default
```

### StreamSender

```c++
 StreamSender(
  const StreamSender &
)=delete
```

### operator=

```c++
StreamSender & operator=(
  const StreamSender &
)=delete
```

### \~StreamSender

```c++
 ~StreamSender()=default
```