Send
Sends data to the specified connection.
- TypeScript
- Python
import { cloudApi, serviceClients, Session } from "@yandex-cloud/nodejs-sdk";
const SendToConnectionRequest =
cloudApi.serverless.apigateway_websocket_connection_service
.SendToConnectionRequest;
const SendToConnectionRequest_DataType =
cloudApi.serverless.apigateway_websocket_connection_service
.SendToConnectionRequest_DataType;
(async () => {
const authToken = process.env["YC_OAUTH_TOKEN"];
const session = new Session({ oauthToken: authToken });
const client = session.client(serviceClients.ConnectionServiceClient);
const result = await client.send(
SendToConnectionRequest.fromPartial({
connectionId: "connectionId",
data: Buffer.from([]),
// type: SendToConnectionRequest_DataType.BINARY
})
);
console.log(result);
})();
import os
import grpc
import yandexcloud
from yandex.cloud.serverless.apigateway.websocket.v1.connection_service_pb2_grpc import (
ConnectionServiceStub,
)
from yandex.cloud.serverless.apigateway.websocket.v1.connection_service_pb2 import (
SendToConnectionRequest,
)
token = os.getenv("YC_OAUTH_TOKEN")
sdk = yandexcloud.SDK(token=token)
service = sdk.client(ConnectionServiceStub)
response = service.Send(
SendToConnectionRequest(
connection_id="connectionId",
data=b"",
# type = SendToConnectionRequest.DataType.BINARY
)
)
print(response)
SendToConnectionRequest
DataType
DATA_TYPE_UNSPECIFIED
BINARY
Binary data.
TEXT
Text data.
connectionId
: string
ID of the connection to which send.
data
: bytes
Data to send.
type
: DataType
Type of the sending data.