|
-
October 9th, 2003, 03:39 AM
#1
accepting a socket connection request
in my main dialog.cpp//dialog-based app
if (serversock.create(8000,SOCK_STREAM,myIP) && serversock.listen())
display OK;
if (serversock.Accept(receivesock,0,0))
display OK;
Is this the method to wait for a connection request?
or should I do it in the OnAccept() of the socket class?
What is the usual method of waiting for connection request and where to accept the request?
-
October 9th, 2003, 04:30 AM
#2
I thing you should use OnAccept() function. If you use Accept() and there will not be any waiting connections this will block your app.
-
October 9th, 2003, 04:36 AM
#3
Actually, this is depending on your socket. If it is a blocking socket, calling Accept() will then wait until there is an incoming connection. If it is nonblocking, Accept will return immediately and any incoming connections will be signalled in OnAccept.
-
October 9th, 2003, 11:41 AM
#4
Originally posted by Richard.J
Actually, this is depending on your socket. If it is a blocking socket, calling Accept() will then wait until there is an incoming connection. If it is nonblocking, Accept will return immediately and any incoming connections will be signalled in OnAccept.
I think I agree on blocking, but don't entirely agree on non-blocking.
For non-blocking, set the socket up to signal your program that there's a request that needs accepting, with a call to WSAAsyncSelect(...FD_ACCEPT...). Then, in your OnAccept() handler, call accept() and test the result against WSAEWOULDBLOCK. If there was not a block, then everthing is fine and the program can continue with communication on the newly-accepted socket. But if there's a block, then the program needs to sit back and wait for OnAccept to be called again.
-Mike
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|