Skip to main content

Send data

Sends data to the specified connection

Function SendData(Val ServerObject, Val ConnectionID, Val Data) Export

ParameterCLI optionTypeRequiredDescription
ServerObject-ArbitraryObject of running server component
ConnectionID-StringConnection identifier
Data-String, BinaryDataSending data
Returns

Map Of KeyAndValue - Execution result

tip

Parameters with Binary data type can also accept file paths on disk and URLs

Caution

NOCLI: this method is not available in CLI version

1C:Enterprise/OneScript code example
// Server start
LaunchPort = 9894;
ServerObject = OPI_WebSocket.StartServer(LaunchPort);

// Client connect to server
ConnectionAddress = "ws://127.0.0.1:9894";
ClientObject = OPI_WebSocket.CreateConnection(ConnectionAddress);

If Not OPI_WebSocket.IsClientObject(ClientObject) Then
Raise OPI_Tools.JSONString(ClientObject);
EndIf;

// Client message send
Message = "Hello!";
OPI_WebSocket.SendTextMessage(ClientObject, Message);

// Receiving the next connection on the server and returning a response
NextMessage = OPI_WebSocket.GetNextConnectionData(ServerObject, 5000);
ConnectionID = NextMessage["connectionId"];

ServerResponse = "Response from server!";
Result = OPI_WebSocket.SendData(ServerObject, ConnectionID, ServerResponse);
Result
{
"result": true
}