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) 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)
Returns

Map Of KeyAndValue - Execution result

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;

// Getting a list of active connections on the server
ConnectionList = OPI_WebSocket.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

// Client message send
CurrentMessage = StrTemplate("Message no. %1", N);
OPI_WebSocket.SendTextMessage(ClientObject, CurrentMessage);

// Receiving an incoming message on the server by ID
Result = OPI_WebSocket.GetConnectionData(ServerObject, ConnectionID, 5000);

EndDo;
Result
{
"address": "127.0.0.1:62972",
"connectionId": "4ece12ce-972c-467f-a1e1-2003e99d362c",
"isActive": true,
"message": "<Binary data>",
"result": true
}