Hi,
I need to create a function in an visual c++ application which will send a specific UDP packet once every second. Within the function(or outside of it actually), I need to listen for a response from a remote computer. Basically it is a message which request statistics from a device, the device will send back a message containing relevant information. Presently I need to verify that the response was sent. I have quickly written some code, but it's problematic. The code ties the CPU up.
CString TempStr;
signed wait_for_response_delay; // in milliseconds
char RcvBuf[MAXPKTSIZE];
int RcvByteCnt;
bool proceed = true;
StatMsgCnt = 0;
StatMsgCnt2 = 0;
RequestStatMsg ReqStatMsg;
// Setup status request message
ReqStatMsg.MsgID = REQUEST_STAT_MSG;
ReqStatMsg.MsgSize = sizeof(RequestStatMsg);
while(true){ // break on button
// Send data packet and close connection
Socket.Send(&ReqStatMsg, sizeof(RequestStatMsg));
StatMsgCnt2++; // update the sent message counter
wait_for_response_delay = 999;
wait_for_response_delay += clock(); // sync with clock
// Check for new messages
while(clock() < wait_for_response_delay){
RcvByteCnt = Socket.Receive(&RcvBuf, MAXPKTSIZE);
} // This is the culprit
// If found, update GUI
if ( RcvByteCnt > 0){
StatMsgCnt++; // update the received message counter
}
else{// Display time and error message to scrolling
textbox}
.
.
.
I'm not much of a windows programmer. Is there a polling function that I can use here? I'd like the program not to be locked up as well, so I can push a 'stop test' button and end the test.
Oh, and while am at it, what's the best method to display the output to a scrolling text box for analysis?
Any suggestions would be appreciated. Thanks!
Rich
I need to create a function in an visual c++ application which will send a specific UDP packet once every second. Within the function(or outside of it actually), I need to listen for a response from a remote computer. Basically it is a message which request statistics from a device, the device will send back a message containing relevant information. Presently I need to verify that the response was sent. I have quickly written some code, but it's problematic. The code ties the CPU up.
CString TempStr;
signed wait_for_response_delay; // in milliseconds
char RcvBuf[MAXPKTSIZE];
int RcvByteCnt;
bool proceed = true;
StatMsgCnt = 0;
StatMsgCnt2 = 0;
RequestStatMsg ReqStatMsg;
// Setup status request message
ReqStatMsg.MsgID = REQUEST_STAT_MSG;
ReqStatMsg.MsgSize = sizeof(RequestStatMsg);
while(true){ // break on button
// Send data packet and close connection
Socket.Send(&ReqStatMsg, sizeof(RequestStatMsg));
StatMsgCnt2++; // update the sent message counter
wait_for_response_delay = 999;
wait_for_response_delay += clock(); // sync with clock
// Check for new messages
while(clock() < wait_for_response_delay){
RcvByteCnt = Socket.Receive(&RcvBuf, MAXPKTSIZE);
} // This is the culprit
// If found, update GUI
if ( RcvByteCnt > 0){
StatMsgCnt++; // update the received message counter
}
else{// Display time and error message to scrolling
textbox}
.
.
.
I'm not much of a windows programmer. Is there a polling function that I can use here? I'd like the program not to be locked up as well, so I can push a 'stop test' button and end the test.
Oh, and while am at it, what's the best method to display the output to a scrolling text box for analysis?
Any suggestions would be appreciated. Thanks!
Rich