recv() returns with 0 - TCP-IP

This is a discussion on recv() returns with 0 - TCP-IP ; Hello. I have a strange problem with TCP sockets. I have a client which connects to the server and sends some 8-byte string message. the send() function returns value 8. Now on the server side when the recv() function unblocks ...

+ Reply to Thread
Results 1 to 16 of 16

Thread: recv() returns with 0

  1. recv() returns with 0

    Hello.

    I have a strange problem with TCP sockets. I have a client which
    connects to the server and sends some 8-byte string message. the
    send() function returns value 8. Now on the server side when the
    recv() function unblocks it returns 0, meaning the client has
    disconnected. But that is not the case since the client loops and no
    close() or shutdown() was called.

    I've also checked the packets with sharkwire and it turns out there
    was no error at all. There's the 3-way handshake upon connection and
    then the PSH packet from the client. After that the server responses
    with ACK and that's that. What could be wrong?

    Greets,
    Luka

  2. Re: recv() returns with 0

    On Jul 28, 6:52*am, luka.napot...@gmail.com wrote:

    > I have a strange problem with TCP sockets. I have a client which
    > connects to the server and sends some 8-byte string message. the
    > send() function returns value 8. Now on the server side when the
    > recv() function unblocks it returns 0, meaning the client has
    > disconnected. But that is not the case since the client loops and no
    > close() or shutdown() was called.
    >
    > I've also checked the packets with sharkwire and it turns out there
    > was no error at all. There's the 3-way handshake upon connection and
    > then the PSH packet from the client. After that the server responses
    > with ACK and that's that. What could be wrong?


    It sounds like a bug in the server. It's hard to be sure though with
    just what you've said.

    DS


  3. Re: recv() returns with 0

    On Jul 28, 3:56*pm, David Schwartz wrote:
    > On Jul 28, 6:52*am, luka.napot...@gmail.com wrote:
    >
    > > I have a strange problem with TCP sockets. I have a client which
    > > connects to the server and sends some 8-byte string message. the
    > > send() function returns value 8. Now on the server side when the
    > > recv() function unblocks it returns 0, meaning the client has
    > > disconnected. But that is not the case since the client loops and no
    > > close() or shutdown() was called.

    >
    > > I've also checked the packets with sharkwire and it turns out there
    > > was no error at all. There's the 3-way handshake upon connection and
    > > then the PSH packet from the client. After that the server responses
    > > with ACK and that's that. What could be wrong?

    >
    > It sounds like a bug in the server. It's hard to be sure though with
    > just what you've said.
    >
    > DS


    I made a syscall trace but between connect() and recvfrom() (or
    sendto() on the client side) there is no single call to close() on the
    socket. Any ideas. I'm getting desperate here

  4. Re: recv() returns with 0

    Any chance your server is non-blocking and it is hiccoughing on an absence
    of data?

    luka.napotnik@gmail.com writes:

    >Hello.


    >I have a strange problem with TCP sockets. I have a client which
    >connects to the server and sends some 8-byte string message. the
    >send() function returns value 8. Now on the server side when the
    >recv() function unblocks it returns 0, meaning the client has
    >disconnected. But that is not the case since the client loops and no
    >close() or shutdown() was called.


    >I've also checked the packets with sharkwire and it turns out there
    >was no error at all. There's the 3-way handshake upon connection and
    >then the PSH packet from the client. After that the server responses
    >with ACK and that's that. What could be wrong?


    >Greets,
    >Luka


  5. Re: recv() returns with 0

    On Jul 28, 7:06*am, luka.napot...@gmail.com wrote:

    > I made a syscall trace but between connect() and recvfrom() (or
    > sendto() on the client side) there is no single call to close() on the
    > socket. Any ideas. I'm getting desperate here


    How did we get from TCP with send/recv to recvfrom/sendto?

    DS

  6. Re: recv() returns with 0

    David Schwartz wrote:
    > On Jul 28, 7:06?am, luka.napot...@gmail.com wrote:


    > > I made a syscall trace but between connect() and recvfrom() (or
    > > sendto() on the client side) there is no single call to close() on the
    > > socket. Any ideas. I'm getting desperate here


    > How did we get from TCP with send/recv to recvfrom/sendto?


    > DS


    --
    Process shall set you free from the need for rational thought.
    these opinions are mine, all mine; HP might not want them anyway...
    feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...

  7. Re: recv() returns with 0

    Grr, editor issues...

    Anyhow, the OP might want to take a packet trace on either sender or
    receiver and see not just what is happening at the system call level,
    but also what is happening on the network.

    rick jones
    --
    The computing industry isn't as much a game of "Follow The Leader" as
    it is one of "Ring Around the Rosy" or perhaps "Duck Duck Goose."
    - Rick Jones
    these opinions are mine, all mine; HP might not want them anyway...
    feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...

  8. Re: recv() returns with 0

    On Jul 28, 4:47*pm, Craig Partridge wrote:
    > Any chance your server is non-blocking and it is hiccoughing on an absence
    > of data?
    >
    > luka.napot...@gmail.com writes:
    > >Hello.
    > >I have a strange problem with TCP sockets. I have a client which
    > >connects to the server and sends some 8-byte string message. the
    > >send() functionreturnsvalue 8. Now on the server side when the
    > >recv() function unblocks itreturns0, meaning the client has
    > >disconnected. But that is not the case since the client loops and no
    > >close() or shutdown() was called.
    > >I've also checked the packets with sharkwire and it turns out there
    > >was no error at all. There's the 3-way handshake upon connection and
    > >then the PSH packet from the client. After that the server responses
    > >with ACK and that's that. What could be wrong?
    > >Greets,
    > >Luka


    No the server/client is blocking

  9. Re: recv() returns with 0

    On Jul 28, 5:36*pm, David Schwartz wrote:
    > On Jul 28, 7:06*am, luka.napot...@gmail.com wrote:
    >
    > > I made a syscall trace but between connect() and recvfrom() (or
    > > sendto() on the client side) there is no single call to close() on the
    > > socket. Any ideas. I'm getting desperate here

    >
    > How did we get from TCP with send/recvto recvfrom/sendto?
    >
    > DS


    It seems send/recv actually call sendto/recvfrom

  10. Re: recv() returns with 0

    luka.napotnik@gmail.com wrote:
    > Now on the server side when the
    > recv() function unblocks it returns 0, meaning the client has
    > disconnected.


    It can also mean that you specified a zero length buffer.

  11. Re: recv() returns with 0

    On Jul 29, 3:03*am, EJP wrote:
    > luka.napot...@gmail.com wrote:
    > > Now on the server side when the
    > >recv() function unblocks itreturns0, meaning the client has
    > > disconnected.

    >
    > It can also mean that you specified a zero length buffer.


    As I said, the client send() returns the right number, which is non-
    zero. Interesting is that the server returns a RESET packet
    immediately after sending an ACK of the clients PUSH packet.

  12. Re: recv() returns with 0

    luka.napotnik@gmail.com wrote:
    >> It can also mean that you specified a zero length buffer.

    >
    > As I said, the client send() returns the right number, which is non-
    > zero.


    I meant that it can return zero if you specify a zero length buffer to
    the recv() method. A zero-length TCP send() doesn't transmit anything,
    so recv() wouldn't return at all.

  13. Re: recv() returns with 0

    On Jul 29, 10:24*am, EJP wrote:
    > luka.napot...@gmail.com wrote:
    > >> It can also mean that you specified a zero length buffer.

    >
    > > As I said, the client send()returnsthe right number, which is non-
    > > zero.

    >
    > I meant that it can return zero if you specify a zero length buffer to
    > therecv() method. A zero-length TCP send() doesn't transmit anything,
    > sorecv() wouldn't return at all.


    That would be impossible. I write to the buffer using sprintf(buffer,
    "blah blah") and the length I give to send() is strlen(buffer) + 1

  14. Re: recv() returns with 0

    On Jul 29, 10:28*am, luka.napot...@gmail.com wrote:
    > On Jul 29, 10:24*am, EJP wrote:
    >
    > > luka.napot...@gmail.com wrote:
    > > >> It can also mean that you specified a zero length buffer.

    >
    > > > As I said, the client send()returnsthe right number, which is non-
    > > > zero.

    >
    > > I meant that it can return zero if you specify a zero length buffer to
    > > therecv() method. A zero-length TCP send() doesn't transmit anything,
    > > sorecv() wouldn't return at all.

    >
    > That would be impossible. I write to the buffer using sprintf(buffer,
    > "blah blah") and the length I give to send() is strlen(buffer) + 1


    The problem is now fixed. I've forgot to initialize something. Tnx
    anyway.

  15. Re: recv() returns with 0

    luka.napotnik@gmail.com wrote:
    > On Jul 29, 10:28 am, luka.napot...@gmail.com wrote:
    >> On Jul 29, 10:24 am, EJP wrote:
    >>>>> It can also mean that you specified a zero length buffer.

    >
    >>> I meant that it can return zero if you specify a zero length buffer to
    >>> the recv() method.

    >
    > The problem is now fixed. I've forgot to initialize something.


    i.e. the length of the buffer for the recv() method?

  16. Re: recv() returns with 0

    Quote Originally Posted by unix View Post
    Hello.

    I have a strange problem with TCP sockets. I have a client which
    connects to the server and sends some 8-byte string message. the
    send() function returns value 8. Now on the server side when the
    recv() function unblocks it returns 0, meaning the client has
    disconnected. But that is not the case since the client loops and no
    close() or shutdown() was called.

    I've also checked the packets with sharkwire and it turns out there
    was no error at all. There's the 3-way handshake upon connection and
    then the PSH packet from the client. After that the server responses
    with ACK and that's that. What could be wrong?

    Greets,
    Luka

    Hi,

    I am facing a similar issue. Can you please let me know the fix you did ?

+ Reply to Thread