beginner seeking help for recv() - Unix

This is a discussion on beginner seeking help for recv() - Unix ; Hello I am writing a C++ / unix application that requires getting data from a socket. This is a bit new to me and i'm stumbling on an issue I have recv() returning some data which is to become headers. ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: beginner seeking help for recv()

  1. beginner seeking help for recv()

    Hello

    I am writing a C++ / unix application that requires getting data from
    a socket. This is a bit new to me and i'm stumbling on an issue

    I have recv() returning some data which is to become headers. My
    program works fine using telnet. I type a line of text, then hit
    return and that text appears where i want it to. However, when using
    somethign like Firefox that sends a bunch of headers at once, my
    program fails to process the data correctly.

    I understand that recv() put data on the socket into a buffer, but how
    is it doing this? How did it know that I wanted to have that data
    after i hit the return key using telnet, even though the buffer was
    not full. Underneath the hood, is there some functionality where
    recv() puts stuff in the butter after a certain period?

    sorry for the ambiguity, I'm struggling with how to ask my question.

  2. Re: beginner seeking help for recv()

    On May 27, 6:05 pm, darren wrote:
    > Hello
    >
    > I am writing a C++ / unix application that requires getting data from
    > a socket. This is a bit new to me and i'm stumbling on an issue
    >
    > I have recv() returning some data which is to become headers. My
    > program works fine using telnet. I type a line of text, then hit
    > return and that text appears where i want it to. However, when using
    > somethign like Firefox that sends a bunch of headers at once, my
    > program fails to process the data correctly.


    paste some code where recv is used.

    >
    > I understand that recv() put data on the socket into a buffer, but how
    > is it doing this? How did it know that I wanted to have that data
    > after i hit the return key using telnet, even though the buffer was
    > not full. Underneath the hood, is there some functionality where
    > recv() puts stuff in the butter after a certain period?


    recv returns as soon as there is some data in the buffer

    http://www.opengroup.org/onlinepubs/...ions/recv.html

    For a very good description of unix networking grab UNPv1 from
    stevens, a very good book on unix networking, with discussions on APIs
    like recv, read etc.
    see in the books section:
    http://groups.google.com/group/comp....4cd8e2c4fc4ce3

    -- paulo

  3. Re: beginner seeking help for recv()

    darren writes:
    > I have recv() returning some data which is to become headers. My
    > program works fine using telnet. I type a line of text, then hit
    > return and that text appears where i want it to. However, when using
    > somethign like Firefox that sends a bunch of headers at once, my
    > program fails to process the data correctly.
    >
    > I understand that recv() put data on the socket into a buffer, but how
    > is it doing this? How did it know that I wanted to have that data
    > after i hit the return key using telnet, even though the buffer was
    > not full.


    It didn't. The telnet client presumably sent the complete line after
    you pressed return.

    > Underneath the hood, is there some functionality where
    > recv() puts stuff in the butter after a certain period?


    This depends on the type of socket which is used. A datagram socket
    preserves message boundaries and each (successful) recv call will
    return exactly the next message, ie the same amount of bytes which
    were used in the corresponding remote send (or write) call. recv on a
    stream ('TCP') socket will usually return after 'some data' is
    available with the exact amount of 'some' depending on the
    implementation and on the situation. The most general true assumption
    in this respect is that each recv call will return at least one byte
    of data. It is possible to change this behaviour either by using recv
    flags, eg MSG_WAITALL, or socket options.

+ Reply to Thread