entropy
2005-10-19 15:45:11 UTC
Vital stats:
- Winsock newbie
- XP Pro SP2
- stock IP stack
- MSVC 6.0
Note: This is a blood-simple question, but I'm dealing with a flooded
basement while trying to keep a project on schedule and need help.
I'm having trouble getting a UDP server using recvfrom() to recognize
when the other party has finished sending data. If I use a blocking
socket, then recvfrom() blocks until data comes in (which is OK) but
then blocks again once the client is done transmitting (which is not
OK).
If I use a non-blocking socket, then the CPU is pegged while in the
pre-transmission "if (WSAGetLastError()==WSAEWOULDBLOCK) continue ;"
loop. Once client transmission is complete, I again revert to pre-
transmission behavior (ie, SOCKET_ERROR and WSAEWOULDBLOCK). I at no
time get a simple '0' from recvfrom().
Since I also get SOCKET_ERROR and WSAEWOULDBLOCK during the client
transmission phase, I'm winding up putting Sleep() calls in between
recvfrom() calls, and counting the number of consecutive SOCKET_ERROR
and WSAEWOULDBLOCKs that occur in order to guess when the client has
ended transmission. It's looking so butt-ugly I figure I'm really
heading down the wrong path.
I've tried using select() prior to transmission to stall on the
socket w/o pegging the CPU -- but it doesn't seem to work on non-
connected sockets.
I can supply code if that helps, but one side effect of the problems
in the basement is that my broadband link is running at about 300bps
(ie, about as fast as an acoustic coupler) so I'm trying to get away
with a simple description of the problem first.
Any links to good descriptions of a well-written UDP server,
articles, or discussion would be greatly appreciated. Sorry for the
Winsock newbie status.
- Winsock newbie
- XP Pro SP2
- stock IP stack
- MSVC 6.0
Note: This is a blood-simple question, but I'm dealing with a flooded
basement while trying to keep a project on schedule and need help.
I'm having trouble getting a UDP server using recvfrom() to recognize
when the other party has finished sending data. If I use a blocking
socket, then recvfrom() blocks until data comes in (which is OK) but
then blocks again once the client is done transmitting (which is not
OK).
If I use a non-blocking socket, then the CPU is pegged while in the
pre-transmission "if (WSAGetLastError()==WSAEWOULDBLOCK) continue ;"
loop. Once client transmission is complete, I again revert to pre-
transmission behavior (ie, SOCKET_ERROR and WSAEWOULDBLOCK). I at no
time get a simple '0' from recvfrom().
Since I also get SOCKET_ERROR and WSAEWOULDBLOCK during the client
transmission phase, I'm winding up putting Sleep() calls in between
recvfrom() calls, and counting the number of consecutive SOCKET_ERROR
and WSAEWOULDBLOCKs that occur in order to guess when the client has
ended transmission. It's looking so butt-ugly I figure I'm really
heading down the wrong path.
I've tried using select() prior to transmission to stall on the
socket w/o pegging the CPU -- but it doesn't seem to work on non-
connected sockets.
I can supply code if that helps, but one side effect of the problems
in the basement is that my broadband link is running at about 300bps
(ie, about as fast as an acoustic coupler) so I'm trying to get away
with a simple description of the problem first.
Any links to good descriptions of a well-written UDP server,
articles, or discussion would be greatly appreciated. Sorry for the
Winsock newbie status.