|
-
May 3rd, 2010, 07:18 PM
#15
Re: CAsyncSocket and Threads
OK, apologies for the denseness, but I feel like I'm back to square 1 with nothing accomplished.
The "entry" point for the SDK is the execute() function, so I've got
Code:
AfxSocketInit();
connected = 0;
s.Create();
if( s.Connect( args[0].getStringValue(), PORT ) == 0 ) {
int e = GetLastError();
logError( "Error code: %d", e );
if( e != WSAEWOULDBLOCK )
return false;
else
logInfo( "Waiting ..." ); // built-in SDK command to print output to the console
}
return true;
I've written my own OnConnect() function that simply says
Code:
CAsyncSocket::OnConnect( nErrorCode ); // saw this in Dr. NewComer's code - why do I have to do this?
Command::logInfo( "Connected!" ); // build-in command to send text output
ShutDown(); // yeah, yeah, not doing anything, just testing, that's all
Close();
The problem is, I never get a message that it was connected; that is, OnConnect() doesn't get called. I do get the output "Waiting ..." so it's definitely getting the WSAEWOULDBLOCK code, but ...
1. I never seem to get a connected notification. Or do I have to do something special to handle that?
2. what's the ordering of the statements? Can I just do:
Code:
mSocket s;
s.Create();
if( s.Connect( ip, port ) == 0 ) {
// error check
}
s.Send(); // so will the code wait to run this until it runs OnConnect(), which, seemingly never gets called?
The other thing, I guess, is why couldn't I run this with CSocket? I realize it blocks, but this is a simple single client, single server setup ... although, I tried rewriting this with CSocket and I'm getting a connect() error of 1, which isn't listed ...
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
|