Google Gruppi non supporta più i nuovi post o le nuove iscrizioni Usenet. I contenuti storici continuano a essere visibili.

RECV () returning -1

11 visualizzazioni
Passa al primo messaggio da leggere

Graziella

da leggere,
1 nov 2010, 04:31:0701/11/10
a
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

da leggere,
1 nov 2010, 07:39:4401/11/10
a
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 nuovi messaggi