When is FD_CONNECT called? - RESOLVED

Started by
1 comment, last by CTEagle 16 years, 10 months ago
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]
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.
enum Bool { True, False, FileNotFound };
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.

This topic is closed to new replies.

Advertisement