CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2011
    Posts
    60

    How do I know I have the full packet from a UDP message?

    This is my first time working with a network!!!! I'm super excited and thank you for taking time to help me out. I thought you could use the recv function to look at parts of a udp message. I have someone sending me a message that could be up to 50000 bytes and in the header of that message he tells me how big the packet is. So I thought I could use recv to receive only the header first, then I could see how big the packet is and I would know when I have to full packet, but this method gave me 10040 socket error messages. So I'm just going to use a buffer that's 50000 bytes and receive the whole packet at once. My question is how will I know I have the full packet?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How do I know I have the full packet from a UDP message?

    Use TCP instead!
    Victor Nijegorodov

  3. #3
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: How do I know I have the full packet from a UDP message?

    I guess you will need to first read up on what exactly the differences are between UDP and TCP.

    Essentially, you cannot do what you were trying here. A UDP Datagram is either received in it's entirety or it isn't received at all. so you can't read only the header to then read the rest.

    Also with UDP, you may not receive the packet at all, or you may receive duplicates. You will probably need some form of flow control.

    Or use TCP as VictorN suggests which will do a lot of the nitty gritty for you in that respect, but then you loose the 'disconnected' flexibility UDP offers (as well as broadcast features).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured