Get connection data
Gets data from the buffer of a specific connection by ID
- Parameters
- Advanced call ?
Function GetConnectionData(Val ServerObject, Val ConnectionID, Val Timeout = 1000) Export
| Parameter | CLI option | Type | Required | Description |
|---|---|---|---|---|
| ServerObject | - | Arbitrary | ✔ | Object of running server component |
| ConnectionID | - | String | ✔ | Connection identifier |
| Timeout | - | Number | ✖ | Waiting period for new data if the queue is empty (in ms) |
Returns
Map Of KeyAndValue - Execution result
This method has no additional advanced call parameters.
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
}