Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Non-Blocking Winsock Sockets

Posted on 1998-07-08
2
Medium Priority
?
827 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 20 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

719 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