Solved

Non-Blocking Winsock Sockets

Posted on 1998-07-08
2
815 Views
Last Modified: 2013-12-03
How can I create a non-blocking socket in VC++ using Winsock (no MFC)?
0
Comment
Question by:VEngineer
  • 2
2 Comments
 
LVL 2

Accepted Solution

by:
WDB earned 10 total points
ID: 1409662
Use This to Create a Non-Blocking Socket

BOOL setSockNonBlocking(HWND hwnd,SOCKET sock)
{
   int  iStatus;

   if ((iStatus =WSAAsyncSelect(sock,hwnd,WSOCK_MESSAGE,                    FD_CONNECT | FD_READ | FD_CLOSE)) > 0) {
      // report error
      return FALSE;
   }
   return(TRUE);
}  // setSockNonBlocking(HWND,SOCKET)
0
 
LVL 2

Expert Comment

by:WDB
ID: 1409663
Or if you need to do this explicitly try:

u_long argp = 1L;
int nRet;
SOCKET s;
.
s = socket(PF_INET,SOCK_DGRAM,0);
if(s==INVALID_SOCKET) // report error

// Make Socket Non-Blocking

nRet = ioctlsocket(s,FIONBIO,(u_long FAR *)&argp);
if(nRet == SOCKET_ERROR) // report error
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question