udp socket options - TCP-IP

This is a discussion on udp socket options - TCP-IP ; Hello, I need to write a UDP application. The first byte in the packet tells me what type of packet it is. Since I have to use UDP I have to use recvfrom and sendto. If I do a recvfrom ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: udp socket options

  1. udp socket options

    Hello,

    I need to write a UDP application. The first byte in the packet tells
    me what type of packet it is. Since I have to use UDP I have to use
    recvfrom and sendto. If I do a recvfrom to read the first byte the
    rest of the buffer is destroyed. I heard there is an UDP socket option
    I can set that will let me read the first byte without destorying the
    rest of the buffer. Is this true? If so what is it?

    Thanks,
    Ben


  2. Re: udp socket options

    On 25 May 2006, bofh1234@hotmail.com wrote:

    > I need to write a UDP application. The first byte in the packet
    > tells me what type of packet it is. Since I have to use UDP I
    > have to use recvfrom and sendto. If I do a recvfrom to read the
    > first byte the rest of the buffer is destroyed. I heard there is
    > an UDP socket option I can set that will let me read the first
    > byte without destorying the rest of the buffer. Is this true? If
    > so what is it?


    Perhaps you're thinking of the recvfrom() flag MSG_PEEK? But I've
    never used it and don't know how it behaves with UDP.

    Dave

    --
    D.a.v.i.d T.i.k.t.i.n
    t.i.k.t.i.n [at] a.d.v.a.n.c.e.d.r.e.l.a.y [dot] c.o.m

  3. Re: udp socket options

    Yes that it is. My brain turned off for a minute. Thanks.


  4. Re: udp socket options

    bofh1234@hotmail.com wrote:
    > Yes that it is. My brain turned off for a minute. Thanks.


    Since you are going to have to be able to (virtually) strip-off that
    first byte anyway when you read the datagram the second time, you
    might as well read the entire datagram to begin with.

    rick jones

    BTW, UDP does not always mean having to use sendto() and recvfrom().
    If you "connect()" the UDP endpoint to the one remote IP/port with
    which you are communicationg, you can use send() and recv().

    All this and more are covered in books like "Unix Network Programming"
    by Stevens, Fenner and Rudof. IMO must reading for anyone writing
    network applications.

    --
    The glass is neither half-empty nor half-full. The glass has a leak.
    The real question is "Can it be patched?"
    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...

  5. Re: udp socket options

    In article ,
    Rick Jones wrote:

    > bofh1234@hotmail.com wrote:
    > > Yes that it is. My brain turned off for a minute. Thanks.

    >
    > Since you are going to have to be able to (virtually) strip-off that
    > first byte anyway when you read the datagram the second time, you
    > might as well read the entire datagram to begin with.


    It sounds like the type byte can be used to determine how big the rest
    of the datagram is, so that he can read it into an appropriately sized
    buffer.

    Although he could simply set his buffer size to the maximum of any of
    the types, and read into that.

    --
    Barry Margolin, barmar@alum.mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    *** PLEASE don't copy me on replies, I'll read them in the group ***

+ Reply to Thread