Stay organized with collectionsSave and categorize content based on your preferences.
visionai::StreamSender
#include <streams.h>
StreamSenderis the client through which users sendPackets to a stream.
Summary
Each instance of theStreamSenderrepresents a single connection to a specific stream. Once created, the user may repeatedly callSendwith newPackets that they want to send to the stream.
Example - Repeatedly sendingPackets to a specific stream.
// First populate the options.StreamSender::Optionsoptions;options.service_connection_options=...;options.stream_id="my-stream";// Create an instance of the `StreamSender`.autostream_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.}autostream_sender=std::move(*stream_sender_statusor);// Now you can repeatedly send Packets.while(true){// Get a new packet from some function or generation mechanism.Packetp=SomeFunctionThatGetsNewPacketsToSend();autostatus=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();
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-27 UTC."],[],[],null,["# visionai::StreamSender Class Reference\n\nvisionai::StreamSender\n======================\n\n`#include \u003cstreams.h\u003e`\n\n[StreamSender](/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.\n\nSummary\n-------\n\nEach instance of the [StreamSender](/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.\n\nExample - Repeatedly sending `Packet`s to a specific stream.\n\n\n```c++\n// First populate the options.\nStreamSender::Options options;\noptions.service_connection_options = ...;\noptions.stream_id = \"my-stream\";\n\n// Create an instance of the `StreamSender`.\nauto stream_sender_statusor = StreamSender::Create(options);\nif (!stream_sender.ok()) {\n// An error occurred during the setup of the sender.\n// You can fix the problem and try again.\n}\nauto stream_sender = std::move(*stream_sender_statusor);\n\n// Now you can repeatedly send Packets.\nwhile (true) {\n // Get a new packet from some function or generation mechanism.\n Packet p = SomeFunctionThatGetsNewPacketsToSend();\n\n auto status = stream_sender-\u003eSend(std::move(p));\n if (!status.ok()) {\n // An error occurred.\n // To retry, you must create a new instance of the sender.\n }\n}\n\n// When there are no more packets to send, remember to destroy the sender.\nstream_sender-\u003ereset();\n```\n\n\u003cbr /\u003e\n\nPublic static functions\n-----------------------\n\n### Create\n\n```c++\nabsl::StatusOr\u003c std::unique_ptr\u003c StreamSender \u003e \u003e Create(\n const Options &\n)\n``` \nCreate a readily usable instance of a [StreamSender](/vision-ai/docs/reference/cpp/class/visionai/stream-sender#classvisionai_1_1_stream_sender).\n\nPublic functions\n----------------\n\n### Send\n\n```c++\nabsl::Status Send(\n Packet packet\n)\n``` \nSend the given `packet` to a stream.\n\nReturns OK on success. Otherwise, returns an error status.\n\nTo retry on a case of failure, you must create a new instance of the [StreamSender](/vision-ai/docs/reference/cpp/class/visionai/stream-sender#classvisionai_1_1_stream_sender) and `Send` through that.\n\nThe first overload blocks until the status of the `Send` is known. The second overload blocks up to `timeout` before returning CANCELLED. \n\n### Send\n\n```c++\nabsl::Status Send(\n Packet packet,\n absl::Duration timeout\n)\n``` \nSend the given `packet` to a stream with a `timeout`.\n\nReturns OK on success. Otherwise, returns an error status.\n\nTo retry on a case of failure, you must create a new instance of the [StreamSender](/vision-ai/docs/reference/cpp/class/visionai/stream-sender#classvisionai_1_1_stream_sender) and `Send` through that.\n\nThe first overload blocks until the status of the `Send` is known. The second overload blocks up to `timeout` before returning CANCELLED. \n\n### StreamSender\n\n```c++\n StreamSender()=default\n``` \n\n### StreamSender\n\n```c++\n StreamSender(\n const StreamSender &\n)=delete\n``` \n\n### operator=\n\n```c++\nStreamSender & operator=(\n const StreamSender &\n)=delete\n``` \n\n### \\~StreamSender\n\n```c++\n ~StreamSender()=default\n```"]]