Netcat: UDP connections don't terminate?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












A simple example, here's my server/host:



nc -ul 192.168.0.2 54 


And the client:



echo "test" | nc -u 192.168.0.2 54


The server will intercept the "test" message, but nc doesn't close. It just remains open until I press Enter or Ctrl+c. Is it possible to have it terminate automatically? Or perhaps include something in the clients message to signify that the transmission has ended?



nc --version
Ncat: Version 7.70 ( https://nmap.org/ncat )


I'm using Debian and macOS.










share|improve this question







New contributor




user321630 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    1
    down vote

    favorite












    A simple example, here's my server/host:



    nc -ul 192.168.0.2 54 


    And the client:



    echo "test" | nc -u 192.168.0.2 54


    The server will intercept the "test" message, but nc doesn't close. It just remains open until I press Enter or Ctrl+c. Is it possible to have it terminate automatically? Or perhaps include something in the clients message to signify that the transmission has ended?



    nc --version
    Ncat: Version 7.70 ( https://nmap.org/ncat )


    I'm using Debian and macOS.










    share|improve this question







    New contributor




    user321630 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      A simple example, here's my server/host:



      nc -ul 192.168.0.2 54 


      And the client:



      echo "test" | nc -u 192.168.0.2 54


      The server will intercept the "test" message, but nc doesn't close. It just remains open until I press Enter or Ctrl+c. Is it possible to have it terminate automatically? Or perhaps include something in the clients message to signify that the transmission has ended?



      nc --version
      Ncat: Version 7.70 ( https://nmap.org/ncat )


      I'm using Debian and macOS.










      share|improve this question







      New contributor




      user321630 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      A simple example, here's my server/host:



      nc -ul 192.168.0.2 54 


      And the client:



      echo "test" | nc -u 192.168.0.2 54


      The server will intercept the "test" message, but nc doesn't close. It just remains open until I press Enter or Ctrl+c. Is it possible to have it terminate automatically? Or perhaps include something in the clients message to signify that the transmission has ended?



      nc --version
      Ncat: Version 7.70 ( https://nmap.org/ncat )


      I'm using Debian and macOS.







      debian ubuntu osx netcat udp






      share|improve this question







      New contributor




      user321630 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      user321630 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      user321630 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Nov 18 at 23:07









      user321630

      362




      362




      New contributor




      user321630 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      user321630 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      user321630 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          While TCP has a concept of connections that have a beginning and an end, UDP does not have that. UDP is a connectionless protocol: an UDP receiver simply waits for incoming packets in a specified UDP port and outputs the content of any arriving UDP packets.



          The receiving nc has no clue about how many packets might be incoming, nor whether those packets should all be coming in from the same host, or from several hosts: it simply receives anything that arrives to the specified UDP port and outputs the contents of the UDP packets to standard output without parsing it in any way until the nc process is interrupted.



          There is not even any built-in guarantee that any packets sent by the client/sender are received in the same order at the receiver end: packets might be lost or reordered on the way. UDP makes no attempt to fix that: it's the job of the thing that is using UDP to deal with all those issues (or ignore them) as appropriate for its purposes.



          You might decide on a specific string, make it mean "end of data" and arrange for another script at the listening end to parse the incoming data and kill the listening nc process when that string is received. In that way, you'll start building your own (perhaps very simple) protocol on top of UDP. And that is exactly what UDP was designed for.



          In a nutshell, the answer to "Is it possible to have nc -ul terminate automatically?" is "No, unless you make something that does it."






          share|improve this answer



























            up vote
            0
            down vote













            netcat has the option -W:



            -W recvlimit Terminate after receiving a number of packets


            So:



            nc -ulW 1 192.168.0.2 54


            But you are using ncat. You can use this workaround:



            nc -ul 192.168.0.2 54 -c 'dd count=1 bs=100000 >&3' 3>&1





            share|improve this answer




















              Your Answer








              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "106"
              ;
              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',
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              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
              );



              );






              user321630 is a new contributor. Be nice, and check out our Code of Conduct.









               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f482632%2fnetcat-udp-connections-dont-terminate%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              0
              down vote













              While TCP has a concept of connections that have a beginning and an end, UDP does not have that. UDP is a connectionless protocol: an UDP receiver simply waits for incoming packets in a specified UDP port and outputs the content of any arriving UDP packets.



              The receiving nc has no clue about how many packets might be incoming, nor whether those packets should all be coming in from the same host, or from several hosts: it simply receives anything that arrives to the specified UDP port and outputs the contents of the UDP packets to standard output without parsing it in any way until the nc process is interrupted.



              There is not even any built-in guarantee that any packets sent by the client/sender are received in the same order at the receiver end: packets might be lost or reordered on the way. UDP makes no attempt to fix that: it's the job of the thing that is using UDP to deal with all those issues (or ignore them) as appropriate for its purposes.



              You might decide on a specific string, make it mean "end of data" and arrange for another script at the listening end to parse the incoming data and kill the listening nc process when that string is received. In that way, you'll start building your own (perhaps very simple) protocol on top of UDP. And that is exactly what UDP was designed for.



              In a nutshell, the answer to "Is it possible to have nc -ul terminate automatically?" is "No, unless you make something that does it."






              share|improve this answer
























                up vote
                0
                down vote













                While TCP has a concept of connections that have a beginning and an end, UDP does not have that. UDP is a connectionless protocol: an UDP receiver simply waits for incoming packets in a specified UDP port and outputs the content of any arriving UDP packets.



                The receiving nc has no clue about how many packets might be incoming, nor whether those packets should all be coming in from the same host, or from several hosts: it simply receives anything that arrives to the specified UDP port and outputs the contents of the UDP packets to standard output without parsing it in any way until the nc process is interrupted.



                There is not even any built-in guarantee that any packets sent by the client/sender are received in the same order at the receiver end: packets might be lost or reordered on the way. UDP makes no attempt to fix that: it's the job of the thing that is using UDP to deal with all those issues (or ignore them) as appropriate for its purposes.



                You might decide on a specific string, make it mean "end of data" and arrange for another script at the listening end to parse the incoming data and kill the listening nc process when that string is received. In that way, you'll start building your own (perhaps very simple) protocol on top of UDP. And that is exactly what UDP was designed for.



                In a nutshell, the answer to "Is it possible to have nc -ul terminate automatically?" is "No, unless you make something that does it."






                share|improve this answer






















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  While TCP has a concept of connections that have a beginning and an end, UDP does not have that. UDP is a connectionless protocol: an UDP receiver simply waits for incoming packets in a specified UDP port and outputs the content of any arriving UDP packets.



                  The receiving nc has no clue about how many packets might be incoming, nor whether those packets should all be coming in from the same host, or from several hosts: it simply receives anything that arrives to the specified UDP port and outputs the contents of the UDP packets to standard output without parsing it in any way until the nc process is interrupted.



                  There is not even any built-in guarantee that any packets sent by the client/sender are received in the same order at the receiver end: packets might be lost or reordered on the way. UDP makes no attempt to fix that: it's the job of the thing that is using UDP to deal with all those issues (or ignore them) as appropriate for its purposes.



                  You might decide on a specific string, make it mean "end of data" and arrange for another script at the listening end to parse the incoming data and kill the listening nc process when that string is received. In that way, you'll start building your own (perhaps very simple) protocol on top of UDP. And that is exactly what UDP was designed for.



                  In a nutshell, the answer to "Is it possible to have nc -ul terminate automatically?" is "No, unless you make something that does it."






                  share|improve this answer












                  While TCP has a concept of connections that have a beginning and an end, UDP does not have that. UDP is a connectionless protocol: an UDP receiver simply waits for incoming packets in a specified UDP port and outputs the content of any arriving UDP packets.



                  The receiving nc has no clue about how many packets might be incoming, nor whether those packets should all be coming in from the same host, or from several hosts: it simply receives anything that arrives to the specified UDP port and outputs the contents of the UDP packets to standard output without parsing it in any way until the nc process is interrupted.



                  There is not even any built-in guarantee that any packets sent by the client/sender are received in the same order at the receiver end: packets might be lost or reordered on the way. UDP makes no attempt to fix that: it's the job of the thing that is using UDP to deal with all those issues (or ignore them) as appropriate for its purposes.



                  You might decide on a specific string, make it mean "end of data" and arrange for another script at the listening end to parse the incoming data and kill the listening nc process when that string is received. In that way, you'll start building your own (perhaps very simple) protocol on top of UDP. And that is exactly what UDP was designed for.



                  In a nutshell, the answer to "Is it possible to have nc -ul terminate automatically?" is "No, unless you make something that does it."







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 19 at 8:29









                  telcoM

                  14.3k11842




                  14.3k11842






















                      up vote
                      0
                      down vote













                      netcat has the option -W:



                      -W recvlimit Terminate after receiving a number of packets


                      So:



                      nc -ulW 1 192.168.0.2 54


                      But you are using ncat. You can use this workaround:



                      nc -ul 192.168.0.2 54 -c 'dd count=1 bs=100000 >&3' 3>&1





                      share|improve this answer
























                        up vote
                        0
                        down vote













                        netcat has the option -W:



                        -W recvlimit Terminate after receiving a number of packets


                        So:



                        nc -ulW 1 192.168.0.2 54


                        But you are using ncat. You can use this workaround:



                        nc -ul 192.168.0.2 54 -c 'dd count=1 bs=100000 >&3' 3>&1





                        share|improve this answer






















                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          netcat has the option -W:



                          -W recvlimit Terminate after receiving a number of packets


                          So:



                          nc -ulW 1 192.168.0.2 54


                          But you are using ncat. You can use this workaround:



                          nc -ul 192.168.0.2 54 -c 'dd count=1 bs=100000 >&3' 3>&1





                          share|improve this answer












                          netcat has the option -W:



                          -W recvlimit Terminate after receiving a number of packets


                          So:



                          nc -ulW 1 192.168.0.2 54


                          But you are using ncat. You can use this workaround:



                          nc -ul 192.168.0.2 54 -c 'dd count=1 bs=100000 >&3' 3>&1






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 19 at 8:54









                          user23013

                          457311




                          457311




















                              user321630 is a new contributor. Be nice, and check out our Code of Conduct.









                               

                              draft saved


                              draft discarded


















                              user321630 is a new contributor. Be nice, and check out our Code of Conduct.












                              user321630 is a new contributor. Be nice, and check out our Code of Conduct.











                              user321630 is a new contributor. Be nice, and check out our Code of Conduct.













                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f482632%2fnetcat-udp-connections-dont-terminate%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

                              How to check contact read email or not when send email to Individual?

                              Bahrain

                              Postfix configuration issue with fips on centos 7; mailgun relay