Skip to main content

Get connection data

Gets data from the buffer of a specific connection by ID

Function GetConnectionData(Val ServerObject, Val ConnectionID, Val Timeout = 1000, Val MaxSize = 8192) Export

ParameterCLI optionTypeRequiredDescription
ServerObject-ArbitraryObject of running server component
ConnectionID-StringConnection identifier
Timeout-NumberWaiting period for new data if the queue is empty (in ms)
MaxSize-NumberMaximum size of data to receive
Returns

Map Of KeyAndValue - Execution result

Caution

NOCLI: this method is not available in CLI version

1C:Enterprise/OneScript code example
LaunchPort = 9877;
ServerObject = OPI_TCP.StartServer(LaunchPort);

// Connect to running server
ConnectionAddress = "127.0.0.1:9877";
ClientObject = OPI_TCP.CreateConnection(ConnectionAddress);

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

// Receive the list of server connections
ConnectionList = OPI_TCP.GetConnectionList(ServerObject);

If Not ConnectionList["result"] Then
Raise OPI_Tools.JSONString(ConnectionList);
EndIf;

If ConnectionList["connections"].Count() = 0 Then
Raise "Connection list is empty";
Else
ConnectionID = ConnectionList["connections"][0]["connectionId"];
EndIf;

For N = 0 To 5 Do

// Send from client
CurrentMessage = StrTemplate("Message no. %1%2", N, Chars.LF);
OPI_TCP.SendLine(ClientObject, CurrentMessage);

// Recieve on server
Result = OPI_TCP.GetConnectionData(ServerObject, ConnectionID, 5000, 8192);

EndDo;
Result
{
"active": true,
"address": "127.0.0.1:52124",
"connectionId": "21d79559-5e07-47ab-9eee-693963ce44da",
"message": "<BinaryData>",
"result": true
}