Solved

Non-Blocking Winsock Sockets

Posted on 1998-07-08
2
812 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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now