recv problem...

recv problem...

Post by Frédéric Violle » Sat, 11 Aug 2001 18:34:20



Hello,

I have problems with the following source :

On the server side :
do {
   iRes = recv(filedesc, bTmp, 3 - iPt, 0);
   iPt += iRes;
  } while(iPt < 3);

On the client side:
send(sock, buff, 3, 0);

I want to retreive 3 bytes in as many tries as necessary. But the send, on
the client side, exits with a "broken pipe". Could someone help me with this
problem please? I'm not too familiar with network programming.

Thanks

 
 
 

recv problem...

Post by Nithyanandha » Sun, 12 Aug 2001 00:47:04



> Hello,

> I have problems with the following source :

> On the server side :
> do {
>    iRes = recv(filedesc, bTmp, 3 - iPt, 0);
>    iPt += iRes;
>   } while(iPt < 3);

> On the client side:
> send(sock, buff, 3, 0);

> I want to retreive 3 bytes in as many tries as necessary. But the send, on
> the client side, exits with a "broken pipe".

That means your server has exited.
There are two approaches to face this.
1] Keep a signal handler for SIGPIPE and do the required .
          OR
2] Ignore SIGPIPE by signal(SIGPIPE, SIG_IGN) and handle the EPIPE error which
was returned due to send().

The second one is preferable.

Quote:> Could someone help me with this
> problem please? I'm not too familiar with network programming.

No problem....More doubts on unix network programming are welcome here.

--

Nithyanand.
Siemens, Bangalore, India.
(Opinions expressed are my own and do not reflect the opinions of my employer,
Siemens)

 
 
 

recv problem...

Post by Barry Margoli » Sun, 12 Aug 2001 03:01:11




>Hello,

>I have problems with the following source :

>On the server side :
>do {
>   iRes = recv(filedesc, bTmp, 3 - iPt, 0);

Shouldn't it be bTmp+Ipt?  Otherwise, each time through the loop you'll
overwrite what you read the previous time.

Also, you're not checking for errors from recv().  If iRes is -1 you got an
error, and if it's 0 you got an unexpected EOF.

Quote:>   iPt += iRes;
>  } while(iPt < 3);

>On the client side:
>send(sock, buff, 3, 0);

>I want to retreive 3 bytes in as many tries as necessary. But the send, on
>the client side, exits with a "broken pipe". Could someone help me with this
>problem please? I'm not too familiar with network programming.

If the send() is getting this error, it probably means that the server
closed the connection before it ever got to the above code.

--

Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

recv problem...

Post by Frédéric Violle » Tue, 14 Aug 2001 16:48:49


In fact, I don't really understand why my server exits... when I replace the
whole do..while loop with a simple recv(filedesc, buff, 3, 0), it works OK.
Why could the server exit the loop before iPt equals 3?

Thanks

Fred




> > Hello,

> > I have problems with the following source :

> > On the server side :
> > do {
> >    iRes = recv(filedesc, bTmp, 3 - iPt, 0);
> >    iPt += iRes;
> >   } while(iPt < 3);

> > On the client side:
> > send(sock, buff, 3, 0);

> > I want to retreive 3 bytes in as many tries as necessary. But the send,
on
> > the client side, exits with a "broken pipe".

> That means your server has exited.
> There are two approaches to face this.
> 1] Keep a signal handler for SIGPIPE and do the required .
>           OR
> 2] Ignore SIGPIPE by signal(SIGPIPE, SIG_IGN) and handle the EPIPE error
which
> was returned due to send().

> The second one is preferable.

> > Could someone help me with this
> > problem please? I'm not too familiar with network programming.

> No problem....More doubts on unix network programming are welcome here.

> --

> Nithyanand.
> Siemens, Bangalore, India.
> (Opinions expressed are my own and do not reflect the opinions of my
employer,
> Siemens)

 
 
 

recv problem...

Post by Frédéric Violle » Tue, 14 Aug 2001 16:52:47






> >Hello,

> >On the client side:
> >send(sock, buff, 3, 0);

> >I want to retreive 3 bytes in as many tries as necessary. But the send,
on
> >the client side, exits with a "broken pipe". Could someone help me with
this
> >problem please? I'm not too familiar with network programming.

> If the send() is getting this error, it probably means that the server
> closed the connection before it ever got to the above code.

Do you know why it would do this? When I replace do {}while() with
recv(filedesc, buff, 3, 0) it works OK.

Thanks

Fred

 
 
 

recv problem...

Post by David Schwart » Wed, 15 Aug 2001 07:09:04


Quote:> > > do {
> > >    iRes = recv(filedesc, bTmp, 3 - iPt, 0);
> > >    iPt += iRes;
> > >   } while(iPt < 3);

        This should be (assuming filedesc is _BLOCKING_):

iPt=0;
do
{
 iRes=recv(filedesc, bTmp, 3-iPt, 0);
 if(iRes<=0) { /* Do something, connection broke */ break; }
 iPt += iRed;

Quote:} while (iPt<3);

        DS
 
 
 

recv problem...

Post by David Schwart » Wed, 15 Aug 2001 07:29:15



> > > > do {
> > > >    iRes = recv(filedesc, bTmp, 3 - iPt, 0);
> > > >    iPt += iRes;
> > > >   } while(iPt < 3);

>         This should be (assuming filedesc is _BLOCKING_):

> iPt=0;
> do
> {
>  iRes=recv(filedesc, bTmp, 3-iPt, 0);
>  if(iRes<=0) { /* Do something, connection broke */ break; }
>  iPt += iRed;
> } while (iPt<3);

>         DS

        Oops, sorry, there's another serious problem in this:

(assuming bTmp is of type 'char *', the 'recv' line should be:

iRes=recv(filedesc, bTmp+iPt, 3-iPt, 0);

        Otherwise successive reads overwrite each other.

        DS

 
 
 

recv problem...

Post by Barry Margoli » Wed, 15 Aug 2001 09:00:41




Quote:>    Oops, sorry, there's another serious problem in this:

>(assuming bTmp is of type 'char *', the 'recv' line should be:

>iRes=recv(filedesc, bTmp+iPt, 3-iPt, 0);

>    Otherwise successive reads overwrite each other.

I pointed that out last week, didn't I?

--

Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

recv problem...

Post by Frédéric Violle » Wed, 15 Aug 2001 16:20:04






> > Oops, sorry, there's another serious problem in this:

> >(assuming bTmp is of type 'char *', the 'recv' line should be:

> >iRes=recv(filedesc, bTmp+iPt, 3-iPt, 0);

> > Otherwise successive reads overwrite each other.

> I pointed that out last week, didn't I?

Indeed... and I answered that, in fact, it didn't matter because I'm
collecting all this information in another buffer anyway... So I still have
this broken pipe problem... I don't understand why the connection breaks:
when I replace the do {...} while() stuff with one recv(filedesc, bTmp, 3,
0), it works fine... why would it be unable to receive the info in more than
one time?

Thanks.

Fred

> --

> Genuity, Woburn, MA
> *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to
newsgroups.
> Please DON'T copy followups to me -- I'll assume it wasn't posted to the

group.
 
 
 

recv problem...

Post by Frédéric Violle » Wed, 15 Aug 2001 16:55:34








> > > Oops, sorry, there's another serious problem in this:

> > >(assuming bTmp is of type 'char *', the 'recv' line should be:

> > >iRes=recv(filedesc, bTmp+iPt, 3-iPt, 0);

> > > Otherwise successive reads overwrite each other.

> > I pointed that out last week, didn't I?

> Indeed... and I answered that, in fact, it didn't matter because I'm
> collecting all this information in another buffer anyway... So I still
have
> this broken pipe problem... I don't understand why the connection breaks:
> when I replace the do {...} while() stuff with one recv(filedesc, bTmp, 3,
> 0), it works fine... why would it be unable to receive the info in more
than
> one time?

In fact, it's quite strange : it works the first time the client connects
and fails after...
Here are the structures of my server and my client :

Server :
bind(socket...)
listen(socket...)
while(1) {
    filedesc = accept(socket)
    do { recv() /* receive 3 bytes */ } while(iPt < 3)
    /* process iBytes of data */
    send(iBytes of data)
    close(filedesc)

Quote:}

Client :
connect(sock)
send(3 bytes)
do { recv() /* receive iBytes */ } while(iPt < iBytes)
close(sock)

The first time I run the client it works fine. After that, the client's recv
sends me error code -19

Fred

 
 
 

recv problem...

Post by Barry Margoli » Thu, 16 Aug 2001 02:08:59




>In fact, it's quite strange : it works the first time the client connects
>and fails after...
>Here are the structures of my server and my client :

Please post the actual code instead of this pseudo-code.  The structure
looks right, so there must be a mistake in the details.

Quote:>The first time I run the client it works fine. After that, the client's recv
>sends me error code -19

Unix doesn't have negative errno values.  Do you mean errno = 19, which is
ENODEV on Solaris?

--

Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

recv problem...

Post by David Schwart » Thu, 16 Aug 2001 02:43:58


Quote:> The first time I run the client it works fine. After that, the client's recv
> sends me error code -19

> Fred

        What is an error code of -19 on your platform?

        DS

 
 
 

1. send() & recv() problem...

Have a problem with some client/server code using send() and
recv(). Initially, the server sends the contents of a file to
the client using - the server uses send() and the client uses
recv(). The client is then prompted to enter a long int which
is then converted to a string and sent to the vendor using
recv(). The vendor uses a call to recv() to retrieve the string
from the client - this call to recv() is placed immeidately
after sending the file information. Currently, by having this
call to recv() in the server code my client now hangs forever.
The call to recv() is not in a loop or any kind...

SERVER
-define sockfd
-send(file info...)
-recv(string...)

CLIENT
-define sockfd
-recv(file info...)
-send(string...)

Any assistance is greatly appreciated.

2. Netscape FastTrack Server Available for Download

3. non-blocking recv() problem when webserver disconnects

4. app479a and Licenses in use

5. socket send/recv problem

6. DLPI and bufmod questions

7. recv() problem?

8. creating linuxppc cd recommendations

9. socket newbie send()/recv() problem

10. recv problem

11. recv() problem, need help!!

12. recv() problem?- need help

13. recv problem