Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSocket connection

Status
Not open for further replies.

shetlandbob

Programmer
Mar 9, 2004
528
0
0
GB
I have a socket that I connect to my server as shown:

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top