shetlandbob
Programmer
I have a socket that I connect to my server as shown:
This will set a timer application to execute in 0.5 seconds, which is caught in the following routine:
This calls a ReceiveSignal routine
The above code works ok, except that the Receive signal waits until it receives a signal before continuing. I want it to check for a signal, then I can look at the signal and consider what to do with what is in the buffer.
I've looked at the socket.IsBlocking() routine, but how can you call that function when the routine stuck waiting for a receive signal?
I also looked at CAsyncSocket, but for some reason it would not connect to my socket??
In summary:
What I am trying to do is open up a socket connection, check the signal every 0.5 seconds, and if it is a set signal, say "UPDATE", then execute a new command.
Any help as always much appreciated
Code:
CSocket socket; // declared in header file
....
...
// In connection routine
...
if ( socket.Create() )
{
if ( socket.Connect ( "0.0.0.00", 3000 ) )
{
socketTimer = SetTimer( SOCKET_TIMER, 500, NULL );
}
}
This will set a timer application to execute in 0.5 seconds, which is caught in the following routine:
Code:
void CMyDlg::OnTimer(UINT nIDEvent)
{
CDialog::OnTimer(nIDEvent);
if ( nIDEvent == SOCKET_TIMER )
{
ReceiveSignal ( );
}
}
This calls a ReceiveSignal routine
Code:
void CMyDlg::ReceiveSignal( void )
{
TCHAR buff[255]
int bytes = socket.Receive( buff, 255 );
buff[bytes] = 0;
if ( strcmp ( buff, "UPDATE" ) == 0 ) DoAnotherRoutine();
else socketTimer = SetTimer( SOCKET_TIMER, 500, NULL );
}
The above code works ok, except that the Receive signal waits until it receives a signal before continuing. I want it to check for a signal, then I can look at the signal and consider what to do with what is in the buffer.
I've looked at the socket.IsBlocking() routine, but how can you call that function when the routine stuck waiting for a receive signal?
I also looked at CAsyncSocket, but for some reason it would not connect to my socket??
In summary:
What I am trying to do is open up a socket connection, check the signal every 0.5 seconds, and if it is a set signal, say "UPDATE", then execute a new command.
Any help as always much appreciated