|
-
April 29th, 2010, 08:23 PM
#5
Re: CAsyncSocket and Threads
On socket errors, you must call GetLastError() to determine the source of the error:
Code:
if( c.Connect( IP, PORT ) == 0 ) {
int iErr = GetLastError();
CString str;
str.Format(_T("Crap: GetLastError = %d"), iErr);
AfxMessageBox( str );
return;
}
Note that the most common error is completely expected and you must code for it: WSAEWOULDBLOCK (which is iErr = 10035). It simply means that Connect() could not complete right away, but it is expected to complete shortly at some indeterminate time in the future, and when it does complete, you will be notified by a call to your override of the OnConnect() virtual function. This mode of "try and wait for completion later" is typical of asynchronous sockets, and indeed is the precise reason why they are called "asynchronous".
Mike
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|