Sign in to follow this  
CTEagle

When is FD_CONNECT called? - RESOLVED

Recommended Posts

I have a chat program that for the most part is working. I am able to send messages between the server and clients. In my code, the socket called sockConnect is between the client and the server. When will this socket call "FD_Connect"? I have added this code to "FD_Connect" in the WinProc for g_frmClient:
case FD_CONNECT:
{
     AddText(hCReceive, "From FD-CONNECT");
}
break;



This code never gets called when I am running my program. FD_READ gets called and works like I would expect it to. The following code is what I use to create and connect sockConnect.
sockaddr_in target;

target.sin_family = AF_INET;     
target.sin_port = htons (5150);   
target.sin_addr.s_addr = inet_addr("127.0.0.1");

//Create Socket
sockConnect = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); 
		
AddText(hCReceive,"\r\n");
AddText(hCReceive, "Socket Created");
			
if (connect(sockConnect,  (SOCKADDR *)&target,  sizeof(target)))
{
     WSACleanup ();
     return;
}
else
{
     WSAAsyncSelect (sockConnect, g_frmClient, MY_CLIENT_MESSAGES, (FD_ACCEPT | FD_CONNECT | FD_READ | FD_CLOSE));
     AddText(hCReceive,"\r\n");
     AddText(hCReceive, "Connected to server");
}



Any thoughts on why FD_CONNECT is never called? Thanks. [Edited by - CTEagle on June 8, 2007 5:55:49 PM]

Share this post


Link to post
Share on other sites
The socket is connected before you call WSAAsyncSelect(), so the select never sees the event. You should do the async select before trying to connect if you want the notification.

Share this post


Link to post
Share on other sites
Thanks hplus. That did the trick. I was beating my head against the wall on this one and as usual, it was a simple fix. Thanks again.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this