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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. about data packet

about data packet

Scheduled Pinned Locked Moved C / C++ / MFC
toolshelpquestion
6 Posts 4 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.
  • M Offline
    M Offline
    Michel_Huang
    wrote on last edited by
    #1

    The data packets received from NIC may have Indefinite length,and among the data may include '\n','\t','\0',and so on . If I do not want to new and delete a char ** every time according to the size of data packet , are there any advanced tools or structurs can be used? Thanks for your help~

    Never to say never~

    C L M 3 Replies Last reply
    0
    • M Michel_Huang

      The data packets received from NIC may have Indefinite length,and among the data may include '\n','\t','\0',and so on . If I do not want to new and delete a char ** every time according to the size of data packet , are there any advanced tools or structurs can be used? Thanks for your help~

      Never to say never~

      C Offline
      C Offline
      chandu004
      wrote on last edited by
      #2

      can you put your question more clearer?

      Suggestion to the members: prefix your main thread subject with [SOLVED] if it is solved. chandu.

      1 Reply Last reply
      0
      • M Michel_Huang

        The data packets received from NIC may have Indefinite length,and among the data may include '\n','\t','\0',and so on . If I do not want to new and delete a char ** every time according to the size of data packet , are there any advanced tools or structurs can be used? Thanks for your help~

        Never to say never~

        L Offline
        L Offline
        led mike
        wrote on last edited by
        #3

        Michel_Huang wrote:

        are there any advanced tools or structurs can be used?

        Yes, and guess how they work? They will new and delete heap memory every time according to the size of data packet. Standard Template Library[^]

        M 1 Reply Last reply
        0
        • M Michel_Huang

          The data packets received from NIC may have Indefinite length,and among the data may include '\n','\t','\0',and so on . If I do not want to new and delete a char ** every time according to the size of data packet , are there any advanced tools or structurs can be used? Thanks for your help~

          Never to say never~

          M Offline
          M Offline
          Mike Dimmick
          wrote on last edited by
          #4

          If you're using UDP packets, the recv API does not allow you to read a bit of the packet then the rest of the packet. It gives you the data up to the size of the buffer you supply then discards the rest. Peeking to find out how much data is present is unreliable. You should define a maximum size packet supported and use a buffer that size. You can simply reuse the buffer once you've processed the data. The maximum packet size supported by the TCP stack can be retrieved with getsockopt, passing the SO_MAX_MSG_SIZE parameter. TCP does not preserve message boundaries. What you see at the receiver can be only part of a single call to send or it can be the result of multiple calls to send. If required, you must put some kind of framing on top of the raw data. Best practice is again to define a fixed size buffer and be prepared to handle any size of data that's returned, which can be as low as one byte. You should probably read the Winsock Programmer's FAQ[^].


          DoEvents: Generating unexpected recursion since 1991

          M 1 Reply Last reply
          0
          • L led mike

            Michel_Huang wrote:

            are there any advanced tools or structurs can be used?

            Yes, and guess how they work? They will new and delete heap memory every time according to the size of data packet. Standard Template Library[^]

            M Offline
            M Offline
            Michel_Huang
            wrote on last edited by
            #5

            ye~ I see ,thank you ~

            Work hard. Laugh often. Keep your honor. Never to say never

            1 Reply Last reply
            0
            • M Mike Dimmick

              If you're using UDP packets, the recv API does not allow you to read a bit of the packet then the rest of the packet. It gives you the data up to the size of the buffer you supply then discards the rest. Peeking to find out how much data is present is unreliable. You should define a maximum size packet supported and use a buffer that size. You can simply reuse the buffer once you've processed the data. The maximum packet size supported by the TCP stack can be retrieved with getsockopt, passing the SO_MAX_MSG_SIZE parameter. TCP does not preserve message boundaries. What you see at the receiver can be only part of a single call to send or it can be the result of multiple calls to send. If required, you must put some kind of framing on top of the raw data. Best practice is again to define a fixed size buffer and be prepared to handle any size of data that's returned, which can be as low as one byte. You should probably read the Winsock Programmer's FAQ[^].


              DoEvents: Generating unexpected recursion since 1991

              M Offline
              M Offline
              Michel_Huang
              wrote on last edited by
              #6

              Thank you ~

              Work hard. Laugh often. Keep your honor. Never to say never

              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