Esempio n. 1
0
static UA_StatusCode CloseSession(UA_Client *client) {
    UA_CloseSessionRequest request;
    UA_CloseSessionRequest_init(&request);

    request.requestHeader.timestamp = UA_DateTime_now();
    request.requestHeader.timeoutHint = 10000;
    request.deleteSubscriptions = UA_TRUE;
    UA_NodeId_copy(&client->authenticationToken, &request.requestHeader.authenticationToken);
    UA_CloseSessionResponse response;
    __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_CLOSESESSIONREQUEST],
                        &response, &UA_TYPES[UA_TYPES_CLOSESESSIONRESPONSE]);

    UA_CloseSessionRequest_deleteMembers(&request);
    UA_CloseSessionResponse_deleteMembers(&response);
    return response.responseHeader.serviceResult; // not deleted
}
Esempio n. 2
0
static UA_Int32 closeSession(ConnectionInfo *connectionInfo) {
	size_t offset = 0;

	UA_ByteString message;
	UA_ByteString_newMembers(&message, 65536);

	UA_CloseSessionRequest rq;
    UA_CloseSessionRequest_init(&rq);

	rq.requestHeader.requestHandle = 1;
	rq.requestHeader.timestamp = UA_DateTime_now();
	rq.requestHeader.timeoutHint = 10000;
	rq.requestHeader.authenticationToken.identifier.numeric = 10;
	rq.requestHeader.authenticationToken.identifierType = UA_NODEIDTYPE_NUMERIC;
	rq.requestHeader.authenticationToken.namespaceIndex = 10;
    rq.deleteSubscriptions = UA_TRUE;

	UA_TcpMessageHeader msghdr;
	msghdr.messageTypeAndFinal = UA_MESSAGETYPEANDFINAL_MSGF;

	UA_NodeId type;
	type.identifier.numeric = 473;
	type.identifierType = UA_NODEIDTYPE_NUMERIC;
	type.namespaceIndex = 0;

	msghdr.messageSize = 16 + UA_TcpMessageHeader_calcSizeBinary(&msghdr) + UA_NodeId_calcSizeBinary(&type) +
                         UA_CloseSessionRequest_calcSizeBinary(&rq);

	UA_TcpMessageHeader_encodeBinary(&msghdr, &message, &offset);
	UA_UInt32_encodeBinary(&connectionInfo->channelId, &message, &offset);
	UA_UInt32_encodeBinary(&connectionInfo->tokenId, &message, &offset);
	UA_UInt32_encodeBinary(&connectionInfo->sequenceHdr.sequenceNumber, &message, &offset);
	UA_UInt32_encodeBinary(&connectionInfo->sequenceHdr.requestId, &message, &offset);
	UA_NodeId_encodeBinary(&type, &message, &offset);
	UA_CloseSessionRequest_encodeBinary(&rq, &message, &offset);

	UA_Int32 sendret = send(connectionInfo->socket, message.data, offset, 0);
	UA_ByteString_deleteMembers(&message);
	UA_CloseSessionRequest_deleteMembers(&rq);
	if(sendret < 0) {
		printf("send closesessionrequest failed");
		return 1;
	}

    return 0;
}