Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. sendto and recvfrom keep grouping packets together??

sendto and recvfrom keep grouping packets together??

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KellyR
    wrote on last edited by
    #1

    Hi, For some reason, if I call multiple sendto's, like this: sendto(sock, etc etc); sendto(sock, etc etc); sendto(sock, etc etc); Then I have a recvfrom loop threaded on my client side, the recvfrom will often receive all the data from multiple sendto's in one 'big' packet and stuff it all together so I can't parse it correctly. What the hell?? Isn't it possible to send a number of TCP packets right after each other and have them received separately?? Thanks! Kelly Ryan

    A 1 Reply Last reply
    0
    • K KellyR

      Hi, For some reason, if I call multiple sendto's, like this: sendto(sock, etc etc); sendto(sock, etc etc); sendto(sock, etc etc); Then I have a recvfrom loop threaded on my client side, the recvfrom will often receive all the data from multiple sendto's in one 'big' packet and stuff it all together so I can't parse it correctly. What the hell?? Isn't it possible to send a number of TCP packets right after each other and have them received separately?? Thanks! Kelly Ryan

      A Offline
      A Offline
      Andrew Walker
      wrote on last edited by
      #2

      No, because TCP is a streaming protocol. Because TCP is reliable (in-order and reliable), you can however wait until you have read a certain number of bytes and then assume that is one 'packet'. For fixed size packets this means you end up with something like read( packet, sizeof(Packet) ) read( packet, sizeof(Packet) ) And for variable size packets: read( packetsize, sizeof(long) ) read( packet, packetsize) read( packetsize, sizeof(long) ) read( packet, packetsize) As an aside, ::send() and ::sendto() are generally used for UDP, whilst TCP normally only uses ::send()


      K 1 Reply Last reply
      0
      • A Andrew Walker

        No, because TCP is a streaming protocol. Because TCP is reliable (in-order and reliable), you can however wait until you have read a certain number of bytes and then assume that is one 'packet'. For fixed size packets this means you end up with something like read( packet, sizeof(Packet) ) read( packet, sizeof(Packet) ) And for variable size packets: read( packetsize, sizeof(long) ) read( packet, packetsize) read( packetsize, sizeof(long) ) read( packet, packetsize) As an aside, ::send() and ::sendto() are generally used for UDP, whilst TCP normally only uses ::send()


        K Offline
        K Offline
        KellyR
        wrote on last edited by
        #3

        Ah, I see. I think I'll add an 'end character' to the end of my sent packets and parse them on the client end by iterating through char by char and each time I hit an 'end character' I'll treat the part before that as a 'packet'. Thanks!! Kelly Ryan

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups