Hi,
If someone has the answer to this I will be most greatful. I cannot get the select() function to work here. My program successfully sends the message and the server responds to this message(I have seen the results on ethereal). What I am trying to accomplish is send out a UDP message(the one defined by RequestStatMsg(which is properly formatted and correct and works fine)), then use the select function as shown below to simply listen for a reply for one second, and log if there is a reply, then repeat. The idea is to test a device to see if it responds to this UDP status request message promptly, and to log failures...testing over long durations(days). This is driving me mad. Thank you for any input you may provide!!
Thank you in advance for your help!
Rich
If someone has the answer to this I will be most greatful. I cannot get the select() function to work here. My program successfully sends the message and the server responds to this message(I have seen the results on ethereal). What I am trying to accomplish is send out a UDP message(the one defined by RequestStatMsg(which is properly formatted and correct and works fine)), then use the select function as shown below to simply listen for a reply for one second, and log if there is a reply, then repeat. The idea is to test a device to see if it responds to this UDP status request message promptly, and to log failures...testing over long durations(days). This is driving me mad. Thank you for any input you may provide!!
Code:
//Global
typedef struct{
unsigned short MsgID; /* REQUEST_STAT_MSG (0x00) */
unsigned short MsgSize; /* Bytes in this message */
}RequestStatMsg;
SOCKADDR_IN remote; // For client
SOCKET sock; // For client
SOCKADDR_IN RecvAddr; // "server usage on PC side"
SOCKET RecvSocket; // for recieving the Stat request message
struct timeval stTimeOut; // Create the timestruct for the
fd_set stReadFDS; // Set the file descriptors
fd_set stXcptFDS;
.
.
.
// everything else isinside <int CJTF_appDlg::OnSend()>
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
RecvSocket = socket(AF_INET, SOCK_DGRAM,IPPROTO_UDP);
.
.
.
while(true)
{
// the sendto works fine
sendto(sock, (char *)&ReqStatMsg,sizeof(ReqStatMsg),
0,(SOCKADDR *)&remote, sizeof(SOCKADDR));
StatMsgSent++;
TempStr.Format("%d", StatMsgSent);
m_MsgSentCnt.SetWindowText(TempStr);
stTimeOut.tv_sec= 1; // 1 sec timeout
stTimeOut.tv_usec=0; // use for milliseconds
// Bind the socket to RED SIDE and the specified port.
RecvAddr.sin_family = AF_INET;
RecvAddr.sin_port = htons(prt); //
RecvAddr.sin_addr.s_addr = inet_addr(IPAddrStr);
bind(RecvSocket, (SOCKADDR *) &RecvAddr,
sizeof(RecvAddr));
// Prep the members
FD_ZERO(&stReadFDS);
FD_ZERO(&stXcptFDS);
FD_SET(RecvSocket, &stReadFDS);
FD_SET(RecvSocket, &stXcptFDS);
// set up to for 1 second
retvalue = select(0,&stReadFDS, NULL, NULL, &stTimeOut);
// handle the case that no message is available
through(timeout 1sec)
// else receive the message
recvfrom(RecvSocket,RecvBuf,BufLen, 0,(SOCKADDR*)
&SenderAddr, &SenderAddrSize);
// This ALWAYS times out after one second, but I know the response is coming back(ethereal). The server simply responds to the clients ip address and port that it sent from. I'm not getting it though???
Rich