problem with development
-
Thank you, i have changed my code in consequences. I have done a sending and a receiving from the agent. I have again a question. I would like to know how i can test and display the message that i received from the agent by the fonction RecvCSCPMessage?
Thank you very much -
Hi!
You should create CSCPMessage object from CSCP_MESSAGE structure filled by RecvNXCPMessage function. After that, you can access to variables inside message via GetVariableXxx methods of class CSCPMessage. If you getting parameter's value from agent, you should be interested in variables VID_RCC - DWORD holding response code, and VID_VALUE - received value as string.
Best regards,
Victor -
Thank you, but i dont understand the difference between RecvCSCPMessage() and RecvNXCPMessage()? I have used the fonction
BOOL AgentConnection::SendMessage(CSCPMessage *pMsg)
{
CSCP_MESSAGE *pRawMsg;
BOOL bResult;pRawMsg = pMsg->CreateMessage();
bResult = (SendEx(m_hSocket, (char *)pRawMsg, ntohl(pRawMsg->dwSize), 0) == (int)ntohl(pRawMsg->dwSize));
free(pRawMsg);
return bResult;
}to send a message to the agent and RecvCSCPMessage to receive a message from an agent. I have just seen the fonction Send NXCPMessage.
Which fonction do i have to use to send and receive a message?Thank you very much
-
CSCP is an old name for NXCP, and it's partially replaces in the code. In latest versions, there are no RecvCSCPMessage() function, only RecvNXCPMessage() - but it's the same function anyway.
Best regards,
Victor -
ok thank you. i have seen that RecvNXCPMessage take in parameters a CSCP_ENCRYPTION_CONTEXT. That means that the message that i receive from the agent is crypted and that i have to decrypted it?
Thank you -
Yes, it could be encrypted, and in that case you should provide correct encryption context. However, if you are not using encryption, you can simple pass NULL.
Best regards,
Victor -
Thank you, i am going to use the fonction SendFileOverNXCP to send a message to the agent and RecvNXCPMessage to receive a message from the agent.
-
In fact i am not sure that the fonction SendFileOverNXCP is used to send a message to the agent.
- How can i do to send a message to the agent and to receive it? I have used RecvNXCPMessage but i dont arrive to see the message sent by the agent.
- What are the steps for the sending and the reception of message?
Thank you very much
-
In general, steps are following:
- create CSCPMessage object
- fill it with necessary variables and set correct command code
- create raw message (CSCP_MESSAGE) vith CSCPMessage::CreateMessage method
- send raw message to agent as usual
- receive response using RecvNXCPMessage function
- create CSCPMessage object from received raw message
- read variables from message object
Best regards,
Victor -
Thank you, it was what i had done. I have send to the Agent the code 0x0097 in order to get the server informations. But which variable did i have to read from the message object for having the information about the server?
Thank you very much
-
You don't need command 0x0097 to read information from agent. You should use CMD_GET_PARAMETER (0x0041) and set name of the parameter to variable VID_PARAMETER (85). Agent will reply with command CMD_REQUEST_COMPLETED (0x001D). First, check variable VID_RCC (28). If it contains 0, then value of requested parameter will be in variable VID_VALUE (21). For example:
CSCPMessage msg;
msg.SetCode(CMD_GET_PARAMETER);
msg.SetId(requestId);
msg.SetVariable(VID_PARAMETER, "Agent.Version");<send message and get response into CSCPMessage *response>
DWORD rcc = response->GetVariableLong(VID_RCC);
if (rcc == ERR_SUCCESS)
{
char buffer[256];
response->GetVariableStr(VID_VALUE, buffer, 256);
// Now buffer contains value of requested parameter
}Best regards,
Victor -
Thank you, i have tried what you told me. For the reception of a message from the agent i have done that:
CSCPMessage *pMsg2=new CSCPMessage(); //classe
CSCP_MESSAGE *pRawMsg2;//structure
CSCP_BUFFER *pMsgBuffer;//structure buffer
int iErr;
TCHAR szBuffer[128];
// Initialize raw message receiving function
pMsgBuffer = (CSCP_BUFFER *)malloc(sizeof(CSCP_BUFFER));
RecvNXCPMessage(socketId, pRawMsg2, pMsgBuffer, RECEIVER_BUFFER_SIZE,0,0,0);
// Allocate space for raw message
pRawMsg2 = (CSCP_MESSAGE *)malloc(RECEIVER_BUFFER_SIZE);
pMsg2 = new CSCPMessage(pRawMsg2);
DWORD rcc = pMsg2->GetVariableLong(VID_RCC);
if (rcc == ERR_SUCCESS)
{
char buffer[256];
pMsg2->GetVariableStr(VID_VALUE, buffer, 256);
// Now buffer contains value of requested parameter
int compteur;
for(compteur=0;compteur<256;compteur++)
{
printf("%c\n",buffer[compteur]);
}//fin du for
}// fin ifBut i always don t managed to read informations. I have done a prinft to see what informations are in the buffer but when i compiled nothing appeared in the buffer.
What do i have to do in order to see the informations that i received from the Agent -
You have missed code for actual message reception. Instead of
// Initialize raw message receiving function pMsgBuffer = (CSCP_BUFFER *)malloc(sizeof(CSCP_BUFFER)); RecvNXCPMessage(socketId, pRawMsg2, pMsgBuffer, RECEIVER_BUFFER_SIZE,0,0,0); // Allocate space for raw message pRawMsg2 = (CSCP_MESSAGE *)malloc(RECEIVER_BUFFER_SIZE); pMsg2 = new CSCPMessage(pRawMsg2);you should have something like
// Initialize raw message receiving function pMsgBuffer = (CSCP_BUFFER *)malloc(sizeof(CSCP_BUFFER)); RecvNXCPMessage(0, NULL, pMsgBuffer, RECEIVER_BUFFER_SIZE,0,0,0); CSCP_ENCRYPTION_CONTEXT *nullContext = NULL; pRawMsg2 = (CSCP_MESSAGE *)malloc(RECEIVER_BUFFER_SIZE); RecvNXCPMessage(socketId, pRawMsg2, pMsgBuffer, RECEIVER_BUFFER_SIZE,&nullContext,NULL,0); pMsg2 = new CSCPMessage(pRawMsg2);Best regards,
Victor -
Hi, thank you and Happy New Year!!
I have done what you said to me but the message send from the agent didn t work again.I have that:
-----------Envoi du message a l agent-----------
code du message : A-----------Reception du message de l agent-----------
¨When i send CMD_GETPAREMETER, i receive ".." with the code that i show you previously.
How can i do to see the parameters?
Thank you again
-
Hello!
Did you set VID_PARAMETER variable before sending CMD_GET_PARAMETER request? You should have something like
msg.SetVariable(VID_PARAMETER, "Agent.Version");
before converting message into binary format and sending. Also, check VID_RCC variable in response message - may be it contains error.
Best regards,
Victor
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login