Click to See Complete Forum and Search --> : Winsock problem!


sinorev
April 9th, 1999, 11:08 AM
Hello
I've done a while loop with select (on my winsock 1.1 socket) to ensure that the entire data length to be taken during a receive is gotten, however, I ran into a problem - when my connection is lagged, I tend to lose data and am unable to get it because receives done with the select()'ed socket occur too quickly before the server can send data back to my email client. I need to get all the data the server sends me when it sends me, despite the fact that I'm lagged. Is there a way I can variably wait until the data arrives? What method would I use to wait in this manner? And how would I determine if there's still data on the server side waiting to be sent?

Thanks :)

sinorev

xchge
April 14th, 1999, 12:49 PM
the winsock'usage has two modes, blocking ans non-blocking. the function---select() is non-block, it's means you can do other things when you wait. the select() can make sure if and which socket receive the data. your can thange the mode you use. after you create a socket with socket(), you can call function ioctl(int socket, u_long cmd, caddr_t data, int lendata), set the cmd is FIONBIO, and data=0, the socket will be set to blocking mode, else data = 1, it's non-blocking.
eg.
int s;
int blockmode;

/* place the socket into blocking mode*/
blockmode = 1;
ioctl(s,FIONBIO,(caddr_t)&blockmode,sizeof(blockmode));
....

my english is too bad to express my thought. sorry!

xchge

April 25th, 1999, 02:51 PM
If your using a TCP stream the reliablity of the protocol insures that you don't drop anything the server sends. If winsock runs out of buffer space it tells the peer to resend the data.

If the peer just gives up sending the data then there's nothing you can do about it.

You can help make the whole thing as efficient as possible by NEVER peeking at the data to see how much is in the buffer. Once you determine a socket is readable recv as much as you can until you get a WSAEWOULDBLOCK error.

WSAAsyncSelect will give you async notifications (through window messages) that the socket is readable (or anything else you want notifications about). That's about as good as it gets with winsock 1.1

Mike