Discussion:
WS2_32 - listen -> accept -> recv -> WSAENOTCONN ?
(too old to reply)
R.Wieser
2017-09-13 08:34:18 UTC
Permalink
Hello All,

I've got a *very* simple setup which listens at a (port 80) socket, accepts
an incoming one and than reads from it.

The problem is that I somethimes (rather dependantly actually, using
Firefox) get a WSAENOTCONN error on the "recv" call (even though I (also)
checked for readability using "select" just before).

My question: what are the circumstances in which this error can pop up ?

Also: how do I check for a non-connected socket (between accepting the
connection and) before calling a "recev" ? Checking a socket for
readability doesn't quite seem to work. :-(

Regards,
Rudy Wieser
Charlie Gibbs
2017-09-13 19:36:56 UTC
Permalink
Post by R.Wieser
Hello All,
I've got a *very* simple setup which listens at a (port 80) socket, accepts
an incoming one and than reads from it.
The problem is that I somethimes (rather dependantly actually, using
Firefox) get a WSAENOTCONN error on the "recv" call (even though I (also)
checked for readability using "select" just before).
My question: what are the circumstances in which this error can pop up ?
Are you properly using listen() to listen for an incoming connection and
accept() to accept it? Recommended reading:

http://beej.us/guide/bgnet/
Post by R.Wieser
Also: how do I check for a non-connected socket (between accepting the
connection and) before calling a "recev" ? Checking a socket for
readability doesn't quite seem to work. :-(
Once you've properly established a connection, you should be good to go.
If the connection has subsequently been closed by the other end, recv()
will return zero.

Again, Beej's Guide to Network Programming is an excellent guide.

Start off with blocking calls and get it working that way first.
Non-blocking calls are a bit more complicated.
--
/~\ ***@kltpzyxm.invalid (Charlie Gibbs)
\ / I'm really at ac.dekanfrus if you read it the right way.
X Top-posted messages will probably be ignored. See RFC1855.
/ \ HTML will DEFINITELY be ignored. Join the ASCII ribbon campaign!
R.Wieser
2017-09-13 20:26:12 UTC
Permalink
Hello Charlie,
Post by Charlie Gibbs
Are you properly using listen() to listen for an incoming connection
and accept() to accept it?
Without a definition of "properly" there is no way I can answer that. But
if you are asking me if the code works than thats a "yes". Many other
connections work flawlessly, returning the expected data.

And its not the error that thats a problem, I already found a way to catch
and handle it (as there is no connection I'm just closing the socket).

The question is, what does the other side (FireFox in this case) do that
causes the "accept" at my side to return a socket, but one thats not
actually connected ?

Regards,
Rudy Wieser
Post by Charlie Gibbs
Post by R.Wieser
Hello All,
I've got a *very* simple setup which listens at a (port 80) socket, accepts
an incoming one and than reads from it.
The problem is that I somethimes (rather dependantly actually, using
Firefox) get a WSAENOTCONN error on the "recv" call (even though I (also)
checked for readability using "select" just before).
My question: what are the circumstances in which this error can pop up ?
Are you properly using listen() to listen for an incoming connection and
http://beej.us/guide/bgnet/
Post by R.Wieser
Also: how do I check for a non-connected socket (between accepting the
connection and) before calling a "recev" ? Checking a socket for
readability doesn't quite seem to work. :-(
Once you've properly established a connection, you should be good to go.
If the connection has subsequently been closed by the other end, recv()
will return zero.
Again, Beej's Guide to Network Programming is an excellent guide.
Start off with blocking calls and get it working that way first.
Non-blocking calls are a bit more complicated.
--
\ / I'm really at ac.dekanfrus if you read it the right way.
X Top-posted messages will probably be ignored. See RFC1855.
/ \ HTML will DEFINITELY be ignored. Join the ASCII ribbon campaig
n!

Loading...