Skip to main content

Read binary data

Reads data from the specified connection

Function ReadBinaryData(Val Connection, Val MaxSize = 0, Val Marker = "", Val Timeout = 5000) Export

ParameterCLI optionTypeRequiredDescription
Connection-ArbitraryConnection, see. CreateConnection
MaxSize-NumberMaximum data size (bytes). 0 > no limit
Marker-String, BinaryDataEnd of message marker. Empty > without marker
Timeout-NumberData waiting timeout (ms). 0 > no limit

Returns: BinaryData - Received data


tip

When working with an infinite stream of incoming data, it is obligatory to specify the MaxSize parameter, because endless data retrieval can cause hang-ups

If the connection is closed, an error occurs, or EOF is detected, the read is terminated in either case

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
    Address    = "45.79.112.203:4242";
Connection = OPI_TCP.CreateConnection(Address);
Message = "Hello server!" + Chars.LF;
Data = ПолучитьДвоичныеДанныеИзСтроки(Message);

OPI_TCP.SendBinaryData(Connection, Data);

// End of message marker to avoid waiting for the end of timeout
Marker = Chars.LF;
Result = OPI_TCP.ReadBinaryData(Connection, , Marker);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

OPI_TCP.CloseConnection(Connection);
Result
"Hello server!\n"