I have created a Dialog application. Acting as Server. And if I click a button the server will start listening for connections from the client.

When I click the button to start listening ,
(I am using the normal socket functions), so after issuing accept the dialog app hangs. So I modified the code in such a way that the socket call for accept does not block using the ioctl socket function on listening socket.
Now the dialog app did not hang.

My problem is , when I tried to connect with the client the connect is successful but the server side cannot accept the incoming connection instead I got an error when I used GetLastError as following:

"A non-blocking socket operation could not be completed immediately."

I want to know how should I able to achieve connection (or) How should I make the accept call succeeded.

/*************************************************/
Here is the part of Server code:

ULONG NonBlock;
listenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

Address.sin_family = AF_INET;
Address.sin_port = htons(listenPort);
Address.sin_addr.s_addr = htonl(INADDR_ANY);

//bind the socket id to the local address
if (bind(listenSocket,(struct sockaddr *) &WdxAddress, sizeof(WdxAddress)) == SOCKET_ERROR)
{
}
if (listen(listenSocket, 100) == SOCKET_ERROR)
{
}

NonBlock = 1;
if (ioctlsocket(listenSocket, FIONBIO, &NonBlock) == SOCKET_ERROR)
{
return;
}

clientAddressLength = sizeof(clientAddress);
if ((connectSocket = accept(listenSocket,(struct sockaddr *) &clientAddress, &clientAddressLength)) < 0)
{
}

/*************************************************/
Here is the Client code:

hostInfo = gethostbyname(szIPAddress);
serverAddress.sin_family = hostInfo->h_addrtype;
memcpy((char *) &serverAddress.sin_addr.s_addr,
hostInfo->h_addr_list[0], myApp->hostInfo->h_length);
serverAddress.sin_port = htons(myApp->serverPort);
if (connect(clientSocket,(struct sockaddr *) &serverAddress,
sizeof(serverAddress)) < 0)
{
return FALSE;
}

/*************************************************/

Can anybody help me in this regard?????
I dont want my Server Dialog app to be hanging until there is a connection is made by the client. Because I want to do some other tasks also with the dialog app meanwhile waiting for connections.