problem with recv function...

B

Babu

Hi all,
I wrote a client program using winsock2.0 . This client
connects to a server and exchanges messages . The problem
is,after some time,recv function call is returning 65535
bytes ( all of them are junk bytes ) and the buffer that I
am using is just 1000 bytes long.The recv continues to
return 65535 junk bytes for a while and causes a memory
exception.I have a few quesions here...

1) What are the possible sources of these junk bytes ?
 
B

Babu

Hi all,
I wrote a client program using winsock2.0 . This client
connects to a server and exchanges messages . The problem
is,after some time,recv function call is returning 65535
bytes ( all of them are junk bytes ) and the buffer that I
am using is just 1000 bytes long.The recv continues to
return 65535 junk bytes for a while and causes a memory
exception.I have a few quesions here...

1) What are the possible sources of these junk bytes ?
Could they be sent from the server ?
2) Is there anyway we can flush the recv's input queue ?
so when I found junk bytes I can clear all the junk
bytes.
 
J

John Phillips

The call is -=not=- returning 65535 bytes; it is returning SOCKET_ERROR.
You then need to call WSAGetLastError() to figure out what the problem is.

Please pay closer attention to the documentation for recv(). You'll note
that the return value for recv() can be either SOCKET_ERROR, -=or=- the
number of bytes received.
 
B

Babu

I am checking for SOCKET_ERROR in the if condition that
follows the recv call.The code is like this...

i = recv ( s,buf,1000, 0 );

if ( i == SOCKET_ERROR )
{
printf("success....");
return ;
}
else
do some thing ;

Had the variable i been set to the SOCKET_ERROR then the
program should come out.Instead of that everytime i has
65535 else part is getting executed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top