Friday, January 11, 2008

How to call callback functions repeatedly ?

ll the callbacks will be in the form of as follows :

WSARecv( AsyncCallback);

if the data is received in a socket, AsyncCallback () fn is being called .
How can we repeatly Read data from socket ? By calling WSARecv() fn in a thread ( which is being called repeatedly)
?

No.. we can achive this by the following


WSARecv(AsyncCallback);


within AsyncCallback()
{

//call the WSARecv() fn based on some condition ...
}

For Example,

AsyncCallback()
{
if( bStop == false)
{
WsaRecv(AsyncCallback);
}
}



Another one way is :


bool bContinueLoop = true;
RecvSocket()
{
WSARecv(AsyncCallback);
}

AsyncCallback()
{
if(bContinueLoop)
{
RecvSocket();
}

}

StopRecvSocket()
{
bContinueLoop = false;
}

No comments: