Below is my code

Socket CSocket,SSocket;
sin_ad.sin_family = AF_INET;//sin.sin_family = PF_INET;
sin_ad.sin_port = htons((u_short)m_Port);
sin_ad.sin_addr.s_addr = INADDR_ANY;    

int s_len = sizeof(sin_ad);

CSocket = accept(SSocket,(struct sockaddr *)&sin_ad, &s_len);

****if (ioctlsocket(CSocket, FIONBIO, &iMode))//iMode is ulong set to 1.
            idc_txtbox.put_SelText("Unblocking of Socket failed");

if (CSocket == INVALID_SOCKET)
   MessageBox("Socket error","ERROR",MB_OK);

Problem is

If the client does not get connected to Server, this accept() portion is still running and i have to manually close the exe.
Once i start the Server, the waiting time for a client is infinite here and am not able to execute other commands after accept().
I want to set a timer after accept(). If the client does not get connected to Server in specific period time, then close the Server Socket.

Understand that Socket by default is in Blocking mode and I have added itoctlSocket to unblock .
I dont know how to code using SO_RCVTIMEO.

I am not using threads for time being in the code and its purely MFC code in Visual Studio in VC++.
Awaiting solutions .

Thanks Andrew

Made few modification in the code by using FD_ZERO,FD_SET and Select and now the prob is solved. Thaks once again.

This question has already been answered. Start a new discussion instead.