• Advertisement
Sign in to follow this  

When is FD_CONNECT called? - RESOLVED

This topic is 3909 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement