Solved

Non-Blocking Winsock Sockets

Posted on 1998-07-08
2
819 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…

756 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