Demultiplexing udp streams from different sources












0















My server is using a single udp socket to receive udp streams from different ip addresses. (All senders send to the same port).
When recv returns on the server with a chunk of data, might that chunk contain bytes from different sources?
Assuming not, is there a reliable way to determine which sender sent that entire chunk?










share|improve this question



























    0















    My server is using a single udp socket to receive udp streams from different ip addresses. (All senders send to the same port).
    When recv returns on the server with a chunk of data, might that chunk contain bytes from different sources?
    Assuming not, is there a reliable way to determine which sender sent that entire chunk?










    share|improve this question

























      0












      0








      0








      My server is using a single udp socket to receive udp streams from different ip addresses. (All senders send to the same port).
      When recv returns on the server with a chunk of data, might that chunk contain bytes from different sources?
      Assuming not, is there a reliable way to determine which sender sent that entire chunk?










      share|improve this question














      My server is using a single udp socket to receive udp streams from different ip addresses. (All senders send to the same port).
      When recv returns on the server with a chunk of data, might that chunk contain bytes from different sources?
      Assuming not, is there a reliable way to determine which sender sent that entire chunk?







      sockets udp






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 25 '18 at 12:22









      David SacksteinDavid Sackstein

      157111




      157111
























          1 Answer
          1






          active

          oldest

          votes


















          1














          In UDP, each chunk received will be exactly what a sender previously passed to ‘send()’ or ‘sendto()’ — unlike TCP, UDP maintains message boundaries.



          You can find out the IP address and port the received packet was sent from by calling ‘recvfrom()’ instead of ‘recv()’. Those values will be written into the ‘struct inaddr_in’ that you provide a pointer to.






          share|improve this answer
























          • Hi Jeremy my question about demultiplexing was answered by Alex F. Your comment however is interesting. What happens if the message is larger than the MTU or larger than the internal socket buffer at the receiver? Surely then the data read by recvfrom will not be a complete message? Are you saying that a read by recvfrom will never contain data from more than one packet but that it is possible that a message may be split into more than one recvfrom call? Can you point to the documentation on this?

            – David Sackstein
            Nov 25 '18 at 17:25













          • I will ask this as a separate question

            – David Sackstein
            Nov 25 '18 at 20:58






          • 1





            If the data passed to send() is greater than the MTU, the packet will be transparently fragmented by the sender, and (if all fragments make it to the receiving machine) transparently re-assembled by the receiver before it is passed to you. (If any of the fragments don’t make it, they will all be silently dropped)

            – Jeremy Friesner
            Nov 26 '18 at 2:46











          • For UDP, the data passed to send() will match the data later returned by recv().

            – Jeremy Friesner
            Nov 26 '18 at 2:47






          • 1





            Only (1) and (4) will be visible to your code; the others you listed will be handled transparently by the tcp stack (ie if there is a checksum mismatch the tcp stack will simply drop the udp packet rather than hand you corrupted data)

            – Jeremy Friesner
            Nov 26 '18 at 20:41











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467382%2fdemultiplexing-udp-streams-from-different-sources%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          In UDP, each chunk received will be exactly what a sender previously passed to ‘send()’ or ‘sendto()’ — unlike TCP, UDP maintains message boundaries.



          You can find out the IP address and port the received packet was sent from by calling ‘recvfrom()’ instead of ‘recv()’. Those values will be written into the ‘struct inaddr_in’ that you provide a pointer to.






          share|improve this answer
























          • Hi Jeremy my question about demultiplexing was answered by Alex F. Your comment however is interesting. What happens if the message is larger than the MTU or larger than the internal socket buffer at the receiver? Surely then the data read by recvfrom will not be a complete message? Are you saying that a read by recvfrom will never contain data from more than one packet but that it is possible that a message may be split into more than one recvfrom call? Can you point to the documentation on this?

            – David Sackstein
            Nov 25 '18 at 17:25













          • I will ask this as a separate question

            – David Sackstein
            Nov 25 '18 at 20:58






          • 1





            If the data passed to send() is greater than the MTU, the packet will be transparently fragmented by the sender, and (if all fragments make it to the receiving machine) transparently re-assembled by the receiver before it is passed to you. (If any of the fragments don’t make it, they will all be silently dropped)

            – Jeremy Friesner
            Nov 26 '18 at 2:46











          • For UDP, the data passed to send() will match the data later returned by recv().

            – Jeremy Friesner
            Nov 26 '18 at 2:47






          • 1





            Only (1) and (4) will be visible to your code; the others you listed will be handled transparently by the tcp stack (ie if there is a checksum mismatch the tcp stack will simply drop the udp packet rather than hand you corrupted data)

            – Jeremy Friesner
            Nov 26 '18 at 20:41
















          1














          In UDP, each chunk received will be exactly what a sender previously passed to ‘send()’ or ‘sendto()’ — unlike TCP, UDP maintains message boundaries.



          You can find out the IP address and port the received packet was sent from by calling ‘recvfrom()’ instead of ‘recv()’. Those values will be written into the ‘struct inaddr_in’ that you provide a pointer to.






          share|improve this answer
























          • Hi Jeremy my question about demultiplexing was answered by Alex F. Your comment however is interesting. What happens if the message is larger than the MTU or larger than the internal socket buffer at the receiver? Surely then the data read by recvfrom will not be a complete message? Are you saying that a read by recvfrom will never contain data from more than one packet but that it is possible that a message may be split into more than one recvfrom call? Can you point to the documentation on this?

            – David Sackstein
            Nov 25 '18 at 17:25













          • I will ask this as a separate question

            – David Sackstein
            Nov 25 '18 at 20:58






          • 1





            If the data passed to send() is greater than the MTU, the packet will be transparently fragmented by the sender, and (if all fragments make it to the receiving machine) transparently re-assembled by the receiver before it is passed to you. (If any of the fragments don’t make it, they will all be silently dropped)

            – Jeremy Friesner
            Nov 26 '18 at 2:46











          • For UDP, the data passed to send() will match the data later returned by recv().

            – Jeremy Friesner
            Nov 26 '18 at 2:47






          • 1





            Only (1) and (4) will be visible to your code; the others you listed will be handled transparently by the tcp stack (ie if there is a checksum mismatch the tcp stack will simply drop the udp packet rather than hand you corrupted data)

            – Jeremy Friesner
            Nov 26 '18 at 20:41














          1












          1








          1







          In UDP, each chunk received will be exactly what a sender previously passed to ‘send()’ or ‘sendto()’ — unlike TCP, UDP maintains message boundaries.



          You can find out the IP address and port the received packet was sent from by calling ‘recvfrom()’ instead of ‘recv()’. Those values will be written into the ‘struct inaddr_in’ that you provide a pointer to.






          share|improve this answer













          In UDP, each chunk received will be exactly what a sender previously passed to ‘send()’ or ‘sendto()’ — unlike TCP, UDP maintains message boundaries.



          You can find out the IP address and port the received packet was sent from by calling ‘recvfrom()’ instead of ‘recv()’. Those values will be written into the ‘struct inaddr_in’ that you provide a pointer to.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 25 '18 at 16:53









          Jeremy FriesnerJeremy Friesner

          39.8k1080164




          39.8k1080164













          • Hi Jeremy my question about demultiplexing was answered by Alex F. Your comment however is interesting. What happens if the message is larger than the MTU or larger than the internal socket buffer at the receiver? Surely then the data read by recvfrom will not be a complete message? Are you saying that a read by recvfrom will never contain data from more than one packet but that it is possible that a message may be split into more than one recvfrom call? Can you point to the documentation on this?

            – David Sackstein
            Nov 25 '18 at 17:25













          • I will ask this as a separate question

            – David Sackstein
            Nov 25 '18 at 20:58






          • 1





            If the data passed to send() is greater than the MTU, the packet will be transparently fragmented by the sender, and (if all fragments make it to the receiving machine) transparently re-assembled by the receiver before it is passed to you. (If any of the fragments don’t make it, they will all be silently dropped)

            – Jeremy Friesner
            Nov 26 '18 at 2:46











          • For UDP, the data passed to send() will match the data later returned by recv().

            – Jeremy Friesner
            Nov 26 '18 at 2:47






          • 1





            Only (1) and (4) will be visible to your code; the others you listed will be handled transparently by the tcp stack (ie if there is a checksum mismatch the tcp stack will simply drop the udp packet rather than hand you corrupted data)

            – Jeremy Friesner
            Nov 26 '18 at 20:41



















          • Hi Jeremy my question about demultiplexing was answered by Alex F. Your comment however is interesting. What happens if the message is larger than the MTU or larger than the internal socket buffer at the receiver? Surely then the data read by recvfrom will not be a complete message? Are you saying that a read by recvfrom will never contain data from more than one packet but that it is possible that a message may be split into more than one recvfrom call? Can you point to the documentation on this?

            – David Sackstein
            Nov 25 '18 at 17:25













          • I will ask this as a separate question

            – David Sackstein
            Nov 25 '18 at 20:58






          • 1





            If the data passed to send() is greater than the MTU, the packet will be transparently fragmented by the sender, and (if all fragments make it to the receiving machine) transparently re-assembled by the receiver before it is passed to you. (If any of the fragments don’t make it, they will all be silently dropped)

            – Jeremy Friesner
            Nov 26 '18 at 2:46











          • For UDP, the data passed to send() will match the data later returned by recv().

            – Jeremy Friesner
            Nov 26 '18 at 2:47






          • 1





            Only (1) and (4) will be visible to your code; the others you listed will be handled transparently by the tcp stack (ie if there is a checksum mismatch the tcp stack will simply drop the udp packet rather than hand you corrupted data)

            – Jeremy Friesner
            Nov 26 '18 at 20:41

















          Hi Jeremy my question about demultiplexing was answered by Alex F. Your comment however is interesting. What happens if the message is larger than the MTU or larger than the internal socket buffer at the receiver? Surely then the data read by recvfrom will not be a complete message? Are you saying that a read by recvfrom will never contain data from more than one packet but that it is possible that a message may be split into more than one recvfrom call? Can you point to the documentation on this?

          – David Sackstein
          Nov 25 '18 at 17:25







          Hi Jeremy my question about demultiplexing was answered by Alex F. Your comment however is interesting. What happens if the message is larger than the MTU or larger than the internal socket buffer at the receiver? Surely then the data read by recvfrom will not be a complete message? Are you saying that a read by recvfrom will never contain data from more than one packet but that it is possible that a message may be split into more than one recvfrom call? Can you point to the documentation on this?

          – David Sackstein
          Nov 25 '18 at 17:25















          I will ask this as a separate question

          – David Sackstein
          Nov 25 '18 at 20:58





          I will ask this as a separate question

          – David Sackstein
          Nov 25 '18 at 20:58




          1




          1





          If the data passed to send() is greater than the MTU, the packet will be transparently fragmented by the sender, and (if all fragments make it to the receiving machine) transparently re-assembled by the receiver before it is passed to you. (If any of the fragments don’t make it, they will all be silently dropped)

          – Jeremy Friesner
          Nov 26 '18 at 2:46





          If the data passed to send() is greater than the MTU, the packet will be transparently fragmented by the sender, and (if all fragments make it to the receiving machine) transparently re-assembled by the receiver before it is passed to you. (If any of the fragments don’t make it, they will all be silently dropped)

          – Jeremy Friesner
          Nov 26 '18 at 2:46













          For UDP, the data passed to send() will match the data later returned by recv().

          – Jeremy Friesner
          Nov 26 '18 at 2:47





          For UDP, the data passed to send() will match the data later returned by recv().

          – Jeremy Friesner
          Nov 26 '18 at 2:47




          1




          1





          Only (1) and (4) will be visible to your code; the others you listed will be handled transparently by the tcp stack (ie if there is a checksum mismatch the tcp stack will simply drop the udp packet rather than hand you corrupted data)

          – Jeremy Friesner
          Nov 26 '18 at 20:41





          Only (1) and (4) will be visible to your code; the others you listed will be handled transparently by the tcp stack (ie if there is a checksum mismatch the tcp stack will simply drop the udp packet rather than hand you corrupted data)

          – Jeremy Friesner
          Nov 26 '18 at 20:41




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467382%2fdemultiplexing-udp-streams-from-different-sources%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Costa Masnaga

          Fotorealismo

          Sidney Franklin