Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

RECV () returning -1

13 views
Skip to first unread message

Graziella

unread,
Nov 1, 2010, 4:31:07 AM11/1/10
to
I am trying to read echo response from the server. But the function
recv is always returning -1. I am new to this, can you help me out??

char buf[BLEN];
char *bptr;
int n;
int buflen;

bptr = buf;
buflen = BLEN;

Int n =recv(s,bptr,buflen,0);
while (n!=0)
{
bptr +=n;
buflen -=n;
n = recv(s,bptr,buflen,0);
}
}

Ulrich Eckhardt

unread,
Nov 1, 2010, 7:39:44 AM11/1/10
to
Graziella wrote:
> I am trying to read echo response from the server. But the function
> recv is always returning -1. I am new to this, can you help me out??

Go to msdn.microsoft.com, search for recv(). You will find the documentation
for that function there, including the meaning of it returning -1. I don't
remember if it was errno, GetLastError() or WSAGetLastError() which you
should use to find further info, but that's documented there, too.

> bptr = buf;
> buflen = BLEN;

Why? You can directly pass an array to recv(), C will pass the address of
its first element instead ("array to pointer decay").

> Int n =recv(s,bptr,buflen,0);
> while (n!=0)

For the record, n==0 is also possible.

Anyhow, recv() returning -1 usually means that the other side closed the
connection without first calling shutdown() to properly flush any buffers.

Uli

--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

0 new messages