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. UPD large messages...

UPD large messages...

Scheduled Pinned Locked Moved C / C++ / MFC
questioncsharpc++performance
10 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.
  • A Offline
    A Offline
    arishri
    wrote on last edited by
    #1

    Hi, Created software for electric switch (one directional) with UPD protocol. At first I created both sides with c#. Worked well but slow, had to restrain my "Transmitter" for the receiver to collect all relevant data. Now for better performance I program a native receiver. All is going well except the "recv" and the "recvfrom" methods only receive 517 bytes of the package size transmitted: (Maximal UDP)65507. How can I receive maximal upd package with a blocking socket?

    L M 2 Replies Last reply
    0
    • A arishri

      Hi, Created software for electric switch (one directional) with UPD protocol. At first I created both sides with c#. Worked well but slow, had to restrain my "Transmitter" for the receiver to collect all relevant data. Now for better performance I program a native receiver. All is going well except the "recv" and the "recvfrom" methods only receive 517 bytes of the package size transmitted: (Maximal UDP)65507. How can I receive maximal upd package with a blocking socket?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You need to keep receiving until there is no more data. TCP and UDP messages get broken up to send across the wire, so you will not always receive the complete message in one go.

      Veni, vidi, abiit domum

      G 1 Reply Last reply
      0
      • A arishri

        Hi, Created software for electric switch (one directional) with UPD protocol. At first I created both sides with c#. Worked well but slow, had to restrain my "Transmitter" for the receiver to collect all relevant data. Now for better performance I program a native receiver. All is going well except the "recv" and the "recvfrom" methods only receive 517 bytes of the package size transmitted: (Maximal UDP)65507. How can I receive maximal upd package with a blocking socket?

        M Offline
        M Offline
        Marco Bertschi
        wrote on last edited by
        #3

        This might have something to do that UDP Messages get broken up into different UDP Packets. For example, the message

        "Hi, I am a UDP message and I maybe get transmitted as multiple UDP packets"

        might be transmitted as

        "Hi, I am a UDP mes"
        "sage and I maybe get transmitted as multiple U"
        "DP packets"

        Due to this you might need to read packets until you KNOW that the message has ended, e.g. by using a fixed message length or a defined control character marking the end of the message. To answer your question: Your socket will remain blocked until the whole message (= every data packet) is received, but you can avoid a block of your whole program by using a separate thread for your socket.

        Veni, vidi, caecus | Everything summarizes to Assembly code

        A 1 Reply Last reply
        0
        • M Marco Bertschi

          This might have something to do that UDP Messages get broken up into different UDP Packets. For example, the message

          "Hi, I am a UDP message and I maybe get transmitted as multiple UDP packets"

          might be transmitted as

          "Hi, I am a UDP mes"
          "sage and I maybe get transmitted as multiple U"
          "DP packets"

          Due to this you might need to read packets until you KNOW that the message has ended, e.g. by using a fixed message length or a defined control character marking the end of the message. To answer your question: Your socket will remain blocked until the whole message (= every data packet) is received, but you can avoid a block of your whole program by using a separate thread for your socket.

          Veni, vidi, caecus | Everything summarizes to Assembly code

          A Offline
          A Offline
          arishri
          wrote on last edited by
          #4

          Thanks, can you give a small code example?

          M L 2 Replies Last reply
          0
          • A arishri

            Thanks, can you give a small code example?

            M Offline
            M Offline
            Marco Bertschi
            wrote on last edited by
            #5

            That depends on which framework you will use. Are you using .Net? MFC? Native C++? Qt?

            Veni, vidi, caecus | Everything summarizes to Assembly code

            1 Reply Last reply
            0
            • A arishri

              Thanks, can you give a small code example?

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              You just need to create a loop that repeats the recv call untill there is no more data.

              Veni, vidi, abiit domum

              A 1 Reply Last reply
              0
              • L Lost User

                You just need to create a loop that repeats the recv call untill there is no more data.

                Veni, vidi, abiit domum

                A Offline
                A Offline
                arishri
                wrote on last edited by
                #7

                Thanks, I'll give it a shot.....

                1 Reply Last reply
                0
                • L Lost User

                  You need to keep receiving until there is no more data. TCP and UDP messages get broken up to send across the wire, so you will not always receive the complete message in one go.

                  Veni, vidi, abiit domum

                  G Offline
                  G Offline
                  Gisle Vanem
                  wrote on last edited by
                  #8

                  UDP messages will not be broken up. But TCP will mostly (possibly except when Nagle is turned off).

                  Gisle V.
                  # rm -vf /bin/laden /bin/rm: success

                  L 2 Replies Last reply
                  0
                  • G Gisle Vanem

                    UDP messages will not be broken up. But TCP will mostly (possibly except when Nagle is turned off).

                    Gisle V.
                    # rm -vf /bin/laden /bin/rm: success

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    Thanks, you are right of course.

                    Veni, vidi, abiit domum

                    1 Reply Last reply
                    0
                    • G Gisle Vanem

                      UDP messages will not be broken up. But TCP will mostly (possibly except when Nagle is turned off).

                      Gisle V.
                      # rm -vf /bin/laden /bin/rm: success

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      Hi, This is incorrect if the packet is transmitted over IPv4. All packets are subject to fragmentation over IPv4 and governed by smallest MTU in the route. Note that if the DF bit is set the router will *not* fragment the packet and will instead send back an IMCP response containing the message "fragmentation needed and DF set". It would be correct to say that routers on an ipv6 network do not fragment and instead the MTU is honored at both receiving end points due to PMTUD. Best Wishes, -David Delaune

                      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