How to use bash to create a socket server and allow multiple clients in the same port?Is there a command like “tee” that limits the file size and treats the output file like a fixed-size queue?Replace log file without affecting “Redirection of stdin and stdout” using nohupHow to avoid sending EOF from a script parsing requests from and sending answers to netcatWhy do I have Established TCP connections with no owner PID?Netcat server/client for a social threadTCP: One PC can connect to other's listening port but not vice versaWhen/how does Linux decides to close a socket on application kill?How to access http server from bash script with existing tcp connection?How can I reliably send data from a TCP port on one computer across the network to a different port on another?Building a Unix socket bridge via TCPSend response based on netcat client requestUnderstanding how MobaXterm keeps an ssh connection alive

Does a creature that is immune to a condition still make a saving throw?

How to back up a running remote server?

How to creep the reader out with what seems like a normal person?

What does "rf" mean in "rfkill"?

Modify locally tikzset

Subtleties of choosing the sequence of tenses in Russian

When India mathematicians did know Euclid's Elements?

Why does nature favour the Laplacian?

Stop and Take a Breath!

Please, smoke with good manners

Was there a Viking Exchange as well as a Columbian one?

How to set the font color of quantity objects (Version 11.3 vs version 12)?

How to replace the "space symbol" (squat-u) in listings?

Why do computer-science majors learn calculus?

Python "triplet" dictionary?

Do generators produce a fixed load?

Mysql fixing root password

Transfer over $10k

Why does processed meat contain preservatives, while canned fish needs not?

Can someone publish a story that happened to you?

Reverse the word in a string with the same order in javascript

Can fracking help reduce CO2?

Has any spacecraft ever had the ability to directly communicate with civilian air traffic control?

How to figure out whether the data is sample data or population data apart from the client's information?



How to use bash to create a socket server and allow multiple clients in the same port?


Is there a command like “tee” that limits the file size and treats the output file like a fixed-size queue?Replace log file without affecting “Redirection of stdin and stdout” using nohupHow to avoid sending EOF from a script parsing requests from and sending answers to netcatWhy do I have Established TCP connections with no owner PID?Netcat server/client for a social threadTCP: One PC can connect to other's listening port but not vice versaWhen/how does Linux decides to close a socket on application kill?How to access http server from bash script with existing tcp connection?How can I reliably send data from a TCP port on one computer across the network to a different port on another?Building a Unix socket bridge via TCPSend response based on netcat client requestUnderstanding how MobaXterm keeps an ssh connection alive






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I have 4 programs, will be increased in the future, these programs have to connect to the same ip:port to send and receive messages at the same time.



Until now I have the socket opened, I also would like to keep the connection alive between the programs and the server.



#!/bin/sh
nc -lvk 88.109.110.161 100 > port100.txt 2>&1









share|improve this question






























    2















    I have 4 programs, will be increased in the future, these programs have to connect to the same ip:port to send and receive messages at the same time.



    Until now I have the socket opened, I also would like to keep the connection alive between the programs and the server.



    #!/bin/sh
    nc -lvk 88.109.110.161 100 > port100.txt 2>&1









    share|improve this question


























      2












      2








      2


      1






      I have 4 programs, will be increased in the future, these programs have to connect to the same ip:port to send and receive messages at the same time.



      Until now I have the socket opened, I also would like to keep the connection alive between the programs and the server.



      #!/bin/sh
      nc -lvk 88.109.110.161 100 > port100.txt 2>&1









      share|improve this question
















      I have 4 programs, will be increased in the future, these programs have to connect to the same ip:port to send and receive messages at the same time.



      Until now I have the socket opened, I also would like to keep the connection alive between the programs and the server.



      #!/bin/sh
      nc -lvk 88.109.110.161 100 > port100.txt 2>&1






      linux networking tcp netcat






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 21 at 16:35









      Jeff Schaller

      45.3k1165148




      45.3k1165148










      asked Apr 21 at 10:44









      Martin Ocando CorleoneMartin Ocando Corleone

      184




      184




















          2 Answers
          2






          active

          oldest

          votes


















          6














          nc does not handle multiple connected clients in parallel and is the wrong tool for this job.
          There are quite a few right tools for this job, including:



          1. Bernstein tcpserver (original or djbwares) or Hoffman tcpserver:
            tcpserver -v -R -H -l 0 88.109.110.161 100 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          2. my tcpserver shim:
            tcpserver -v 88.109.110.161 100 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          3. my UCSPI-TCP tools:
            tcp-socket-listen 88.109.110.161 100 tcp-socket-accept --verbose sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          4. Bercot s6-tcpserver4:
            s6-tcpserver4 -v 2 88.109.110.161 100 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          5. Bercot s6-networking tools:
            s6-tcpserver4-socketbinder 88.109.110.161 100 s6-tcpserver4d -v 2 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          6. Pape tcpsvd:
            tcpsvd -v 88.109.110.161 100 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          7. Sampson onenetd:
            onenetd -v 88.109.110.161 100 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          And one can substitute multilog, s6-log, svlogd, or tinylog for cyclog.



          Further reading



          • Protocol:

            • Jonathan de Boyne Pollard (2016). The gen on the UNIX Client-Server Program Interface. Frequently Given Answers.

            • Daniel J. Bernstein (1996). UNIX Client-Server Program Interface. cr.yp.to.


          • toolsets:

            • Daniel J. Bernstein. ucspi-tcp. cr.yp.to.

            • Erwin Hoffmann. ucspi-tcp6. fehcom.de.


            • s6-networking. Laurent Bercot. skarnet.org.

            • Jonathan de Boyne Pollard (2019). nosh. Softwares.

            • Jonathan de Boyne Pollard (2019). djbwares. Softwares.


            • ipsvd. Gerrit Pape. smarden.org.


            • onenetd. Adam Sampson. offog.org.


          • reference manuals:

            • Daniel J. Bernstein. The tcpserver program. ucspi-tcp.

            • Erwin Hoffmann. tcpserver. ucspi-tcp6. fehcom.de.


            • s6-tcpserver4. Laurent Bercot. s6-networking. skarnet.org.


            • tcpsvd. ipsvd. Gerrit Pape. smarden.org.

            • Jonathan de Boyne Pollard (2019). tcpserver. djbwares. Softwares.

            • Jonathan de Boyne Pollard (2019). tcp-socket-listen. nosh Guide. Softwares.

            • Jonathan de Boyne Pollard (2019). tcp-socket-accept. nosh Guide. Softwares.

            • Jonathan de Boyne Pollard (2019). tcpserver. nosh Guide. Softwares.


          • Logging:

            • https://unix.stackexchange.com/a/340631/5132

            • https://unix.stackexchange.com/a/505854/5132






          share|improve this answer

























          • One can also consider use a load balancing proxy like haproxy in front of the servelets to direct tcp streams based on some filterable information or in a load balance configuration with maxconn = 1

            – crasic
            Apr 21 at 20:24












          • I will test them and will let you know how it goes

            – Martin Ocando Corleone
            Apr 22 at 13:06


















          0














          It's a real pity that there's no standard/readily available tool for such basic task, but if you're not on some embedded system and have some scripting language like perl or python available, you can quickly put something together:



          tcpsrv:



          #! /usr/bin/perl
          use strict;
          use IO::Socket::INET6;
          die "usage: $0 host:port cmd args ... n" unless @ARGV >= 2;
          my $h = shift;
          my $s=new IO::Socket::INET6(ReusePort=>1, Listen=>6, LocalAddr=>$h)
          or die "IO::Socket::INET($h): $!";
          warn "listening on ", $s->sockhost, "/", $s->sockport, "n";
          $SIGCHLD = sub use POSIX qw(WNOHANG); 1 while waitpid(-1, WNOHANG) > 0 ;
          while(1)
          my $a = $s->accept or do die "accept: $!" unless $!EINTR; next ;
          warn "connection from ", $a->peerhost, "/", $a->peerport, "n";
          die unless defined(my $p = fork);
          close($a), next if $p;
          open STDIN, "<&", $a and open STDOUT, ">&", $a or die "dup: $!";
          close $s and close $a or die "close: $!";
          exec(@ARGV); die "exec @ARGV: $!";



          Usage: tcpsrv host:port cmd



          This will listen on host:port, and anytime a client connects to host:host, it will fork & exec cmd with its stdin and stdout redirected from/to the connection:



          tcpsrv :9999 ls .
          tcpsrv 127.0.0.1:7000 uptime
          tcpsrv [::]:7000 uptime
          tcpsrv 88.109.110.161:2000 'cat > port2000.txt'





          share|improve this answer

























          • Never worked with perl, but I will do the attempt, thanks

            – Martin Ocando Corleone
            Apr 22 at 13:07











          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',
          autoActivateHeartbeat: false,
          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
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f513648%2fhow-to-use-bash-to-create-a-socket-server-and-allow-multiple-clients-in-the-same%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









          6














          nc does not handle multiple connected clients in parallel and is the wrong tool for this job.
          There are quite a few right tools for this job, including:



          1. Bernstein tcpserver (original or djbwares) or Hoffman tcpserver:
            tcpserver -v -R -H -l 0 88.109.110.161 100 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          2. my tcpserver shim:
            tcpserver -v 88.109.110.161 100 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          3. my UCSPI-TCP tools:
            tcp-socket-listen 88.109.110.161 100 tcp-socket-accept --verbose sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          4. Bercot s6-tcpserver4:
            s6-tcpserver4 -v 2 88.109.110.161 100 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          5. Bercot s6-networking tools:
            s6-tcpserver4-socketbinder 88.109.110.161 100 s6-tcpserver4d -v 2 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          6. Pape tcpsvd:
            tcpsvd -v 88.109.110.161 100 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          7. Sampson onenetd:
            onenetd -v 88.109.110.161 100 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          And one can substitute multilog, s6-log, svlogd, or tinylog for cyclog.



          Further reading



          • Protocol:

            • Jonathan de Boyne Pollard (2016). The gen on the UNIX Client-Server Program Interface. Frequently Given Answers.

            • Daniel J. Bernstein (1996). UNIX Client-Server Program Interface. cr.yp.to.


          • toolsets:

            • Daniel J. Bernstein. ucspi-tcp. cr.yp.to.

            • Erwin Hoffmann. ucspi-tcp6. fehcom.de.


            • s6-networking. Laurent Bercot. skarnet.org.

            • Jonathan de Boyne Pollard (2019). nosh. Softwares.

            • Jonathan de Boyne Pollard (2019). djbwares. Softwares.


            • ipsvd. Gerrit Pape. smarden.org.


            • onenetd. Adam Sampson. offog.org.


          • reference manuals:

            • Daniel J. Bernstein. The tcpserver program. ucspi-tcp.

            • Erwin Hoffmann. tcpserver. ucspi-tcp6. fehcom.de.


            • s6-tcpserver4. Laurent Bercot. s6-networking. skarnet.org.


            • tcpsvd. ipsvd. Gerrit Pape. smarden.org.

            • Jonathan de Boyne Pollard (2019). tcpserver. djbwares. Softwares.

            • Jonathan de Boyne Pollard (2019). tcp-socket-listen. nosh Guide. Softwares.

            • Jonathan de Boyne Pollard (2019). tcp-socket-accept. nosh Guide. Softwares.

            • Jonathan de Boyne Pollard (2019). tcpserver. nosh Guide. Softwares.


          • Logging:

            • https://unix.stackexchange.com/a/340631/5132

            • https://unix.stackexchange.com/a/505854/5132






          share|improve this answer

























          • One can also consider use a load balancing proxy like haproxy in front of the servelets to direct tcp streams based on some filterable information or in a load balance configuration with maxconn = 1

            – crasic
            Apr 21 at 20:24












          • I will test them and will let you know how it goes

            – Martin Ocando Corleone
            Apr 22 at 13:06















          6














          nc does not handle multiple connected clients in parallel and is the wrong tool for this job.
          There are quite a few right tools for this job, including:



          1. Bernstein tcpserver (original or djbwares) or Hoffman tcpserver:
            tcpserver -v -R -H -l 0 88.109.110.161 100 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          2. my tcpserver shim:
            tcpserver -v 88.109.110.161 100 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          3. my UCSPI-TCP tools:
            tcp-socket-listen 88.109.110.161 100 tcp-socket-accept --verbose sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          4. Bercot s6-tcpserver4:
            s6-tcpserver4 -v 2 88.109.110.161 100 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          5. Bercot s6-networking tools:
            s6-tcpserver4-socketbinder 88.109.110.161 100 s6-tcpserver4d -v 2 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          6. Pape tcpsvd:
            tcpsvd -v 88.109.110.161 100 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          7. Sampson onenetd:
            onenetd -v 88.109.110.161 100 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          And one can substitute multilog, s6-log, svlogd, or tinylog for cyclog.



          Further reading



          • Protocol:

            • Jonathan de Boyne Pollard (2016). The gen on the UNIX Client-Server Program Interface. Frequently Given Answers.

            • Daniel J. Bernstein (1996). UNIX Client-Server Program Interface. cr.yp.to.


          • toolsets:

            • Daniel J. Bernstein. ucspi-tcp. cr.yp.to.

            • Erwin Hoffmann. ucspi-tcp6. fehcom.de.


            • s6-networking. Laurent Bercot. skarnet.org.

            • Jonathan de Boyne Pollard (2019). nosh. Softwares.

            • Jonathan de Boyne Pollard (2019). djbwares. Softwares.


            • ipsvd. Gerrit Pape. smarden.org.


            • onenetd. Adam Sampson. offog.org.


          • reference manuals:

            • Daniel J. Bernstein. The tcpserver program. ucspi-tcp.

            • Erwin Hoffmann. tcpserver. ucspi-tcp6. fehcom.de.


            • s6-tcpserver4. Laurent Bercot. s6-networking. skarnet.org.


            • tcpsvd. ipsvd. Gerrit Pape. smarden.org.

            • Jonathan de Boyne Pollard (2019). tcpserver. djbwares. Softwares.

            • Jonathan de Boyne Pollard (2019). tcp-socket-listen. nosh Guide. Softwares.

            • Jonathan de Boyne Pollard (2019). tcp-socket-accept. nosh Guide. Softwares.

            • Jonathan de Boyne Pollard (2019). tcpserver. nosh Guide. Softwares.


          • Logging:

            • https://unix.stackexchange.com/a/340631/5132

            • https://unix.stackexchange.com/a/505854/5132






          share|improve this answer

























          • One can also consider use a load balancing proxy like haproxy in front of the servelets to direct tcp streams based on some filterable information or in a load balance configuration with maxconn = 1

            – crasic
            Apr 21 at 20:24












          • I will test them and will let you know how it goes

            – Martin Ocando Corleone
            Apr 22 at 13:06













          6












          6








          6







          nc does not handle multiple connected clients in parallel and is the wrong tool for this job.
          There are quite a few right tools for this job, including:



          1. Bernstein tcpserver (original or djbwares) or Hoffman tcpserver:
            tcpserver -v -R -H -l 0 88.109.110.161 100 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          2. my tcpserver shim:
            tcpserver -v 88.109.110.161 100 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          3. my UCSPI-TCP tools:
            tcp-socket-listen 88.109.110.161 100 tcp-socket-accept --verbose sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          4. Bercot s6-tcpserver4:
            s6-tcpserver4 -v 2 88.109.110.161 100 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          5. Bercot s6-networking tools:
            s6-tcpserver4-socketbinder 88.109.110.161 100 s6-tcpserver4d -v 2 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          6. Pape tcpsvd:
            tcpsvd -v 88.109.110.161 100 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          7. Sampson onenetd:
            onenetd -v 88.109.110.161 100 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          And one can substitute multilog, s6-log, svlogd, or tinylog for cyclog.



          Further reading



          • Protocol:

            • Jonathan de Boyne Pollard (2016). The gen on the UNIX Client-Server Program Interface. Frequently Given Answers.

            • Daniel J. Bernstein (1996). UNIX Client-Server Program Interface. cr.yp.to.


          • toolsets:

            • Daniel J. Bernstein. ucspi-tcp. cr.yp.to.

            • Erwin Hoffmann. ucspi-tcp6. fehcom.de.


            • s6-networking. Laurent Bercot. skarnet.org.

            • Jonathan de Boyne Pollard (2019). nosh. Softwares.

            • Jonathan de Boyne Pollard (2019). djbwares. Softwares.


            • ipsvd. Gerrit Pape. smarden.org.


            • onenetd. Adam Sampson. offog.org.


          • reference manuals:

            • Daniel J. Bernstein. The tcpserver program. ucspi-tcp.

            • Erwin Hoffmann. tcpserver. ucspi-tcp6. fehcom.de.


            • s6-tcpserver4. Laurent Bercot. s6-networking. skarnet.org.


            • tcpsvd. ipsvd. Gerrit Pape. smarden.org.

            • Jonathan de Boyne Pollard (2019). tcpserver. djbwares. Softwares.

            • Jonathan de Boyne Pollard (2019). tcp-socket-listen. nosh Guide. Softwares.

            • Jonathan de Boyne Pollard (2019). tcp-socket-accept. nosh Guide. Softwares.

            • Jonathan de Boyne Pollard (2019). tcpserver. nosh Guide. Softwares.


          • Logging:

            • https://unix.stackexchange.com/a/340631/5132

            • https://unix.stackexchange.com/a/505854/5132






          share|improve this answer















          nc does not handle multiple connected clients in parallel and is the wrong tool for this job.
          There are quite a few right tools for this job, including:



          1. Bernstein tcpserver (original or djbwares) or Hoffman tcpserver:
            tcpserver -v -R -H -l 0 88.109.110.161 100 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          2. my tcpserver shim:
            tcpserver -v 88.109.110.161 100 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          3. my UCSPI-TCP tools:
            tcp-socket-listen 88.109.110.161 100 tcp-socket-accept --verbose sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          4. Bercot s6-tcpserver4:
            s6-tcpserver4 -v 2 88.109.110.161 100 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          5. Bercot s6-networking tools:
            s6-tcpserver4-socketbinder 88.109.110.161 100 s6-tcpserver4d -v 2 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          6. Pape tcpsvd:
            tcpsvd -v 88.109.110.161 100 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          7. Sampson onenetd:
            onenetd -v 88.109.110.161 100 sh -c 'exec cat 1>&2' 2>&1 |
            cyclog port100/


          And one can substitute multilog, s6-log, svlogd, or tinylog for cyclog.



          Further reading



          • Protocol:

            • Jonathan de Boyne Pollard (2016). The gen on the UNIX Client-Server Program Interface. Frequently Given Answers.

            • Daniel J. Bernstein (1996). UNIX Client-Server Program Interface. cr.yp.to.


          • toolsets:

            • Daniel J. Bernstein. ucspi-tcp. cr.yp.to.

            • Erwin Hoffmann. ucspi-tcp6. fehcom.de.


            • s6-networking. Laurent Bercot. skarnet.org.

            • Jonathan de Boyne Pollard (2019). nosh. Softwares.

            • Jonathan de Boyne Pollard (2019). djbwares. Softwares.


            • ipsvd. Gerrit Pape. smarden.org.


            • onenetd. Adam Sampson. offog.org.


          • reference manuals:

            • Daniel J. Bernstein. The tcpserver program. ucspi-tcp.

            • Erwin Hoffmann. tcpserver. ucspi-tcp6. fehcom.de.


            • s6-tcpserver4. Laurent Bercot. s6-networking. skarnet.org.


            • tcpsvd. ipsvd. Gerrit Pape. smarden.org.

            • Jonathan de Boyne Pollard (2019). tcpserver. djbwares. Softwares.

            • Jonathan de Boyne Pollard (2019). tcp-socket-listen. nosh Guide. Softwares.

            • Jonathan de Boyne Pollard (2019). tcp-socket-accept. nosh Guide. Softwares.

            • Jonathan de Boyne Pollard (2019). tcpserver. nosh Guide. Softwares.


          • Logging:

            • https://unix.stackexchange.com/a/340631/5132

            • https://unix.stackexchange.com/a/505854/5132







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Apr 21 at 12:34

























          answered Apr 21 at 12:27









          JdeBPJdeBP

          39k480187




          39k480187












          • One can also consider use a load balancing proxy like haproxy in front of the servelets to direct tcp streams based on some filterable information or in a load balance configuration with maxconn = 1

            – crasic
            Apr 21 at 20:24












          • I will test them and will let you know how it goes

            – Martin Ocando Corleone
            Apr 22 at 13:06

















          • One can also consider use a load balancing proxy like haproxy in front of the servelets to direct tcp streams based on some filterable information or in a load balance configuration with maxconn = 1

            – crasic
            Apr 21 at 20:24












          • I will test them and will let you know how it goes

            – Martin Ocando Corleone
            Apr 22 at 13:06
















          One can also consider use a load balancing proxy like haproxy in front of the servelets to direct tcp streams based on some filterable information or in a load balance configuration with maxconn = 1

          – crasic
          Apr 21 at 20:24






          One can also consider use a load balancing proxy like haproxy in front of the servelets to direct tcp streams based on some filterable information or in a load balance configuration with maxconn = 1

          – crasic
          Apr 21 at 20:24














          I will test them and will let you know how it goes

          – Martin Ocando Corleone
          Apr 22 at 13:06





          I will test them and will let you know how it goes

          – Martin Ocando Corleone
          Apr 22 at 13:06













          0














          It's a real pity that there's no standard/readily available tool for such basic task, but if you're not on some embedded system and have some scripting language like perl or python available, you can quickly put something together:



          tcpsrv:



          #! /usr/bin/perl
          use strict;
          use IO::Socket::INET6;
          die "usage: $0 host:port cmd args ... n" unless @ARGV >= 2;
          my $h = shift;
          my $s=new IO::Socket::INET6(ReusePort=>1, Listen=>6, LocalAddr=>$h)
          or die "IO::Socket::INET($h): $!";
          warn "listening on ", $s->sockhost, "/", $s->sockport, "n";
          $SIGCHLD = sub use POSIX qw(WNOHANG); 1 while waitpid(-1, WNOHANG) > 0 ;
          while(1)
          my $a = $s->accept or do die "accept: $!" unless $!EINTR; next ;
          warn "connection from ", $a->peerhost, "/", $a->peerport, "n";
          die unless defined(my $p = fork);
          close($a), next if $p;
          open STDIN, "<&", $a and open STDOUT, ">&", $a or die "dup: $!";
          close $s and close $a or die "close: $!";
          exec(@ARGV); die "exec @ARGV: $!";



          Usage: tcpsrv host:port cmd



          This will listen on host:port, and anytime a client connects to host:host, it will fork & exec cmd with its stdin and stdout redirected from/to the connection:



          tcpsrv :9999 ls .
          tcpsrv 127.0.0.1:7000 uptime
          tcpsrv [::]:7000 uptime
          tcpsrv 88.109.110.161:2000 'cat > port2000.txt'





          share|improve this answer

























          • Never worked with perl, but I will do the attempt, thanks

            – Martin Ocando Corleone
            Apr 22 at 13:07















          0














          It's a real pity that there's no standard/readily available tool for such basic task, but if you're not on some embedded system and have some scripting language like perl or python available, you can quickly put something together:



          tcpsrv:



          #! /usr/bin/perl
          use strict;
          use IO::Socket::INET6;
          die "usage: $0 host:port cmd args ... n" unless @ARGV >= 2;
          my $h = shift;
          my $s=new IO::Socket::INET6(ReusePort=>1, Listen=>6, LocalAddr=>$h)
          or die "IO::Socket::INET($h): $!";
          warn "listening on ", $s->sockhost, "/", $s->sockport, "n";
          $SIGCHLD = sub use POSIX qw(WNOHANG); 1 while waitpid(-1, WNOHANG) > 0 ;
          while(1)
          my $a = $s->accept or do die "accept: $!" unless $!EINTR; next ;
          warn "connection from ", $a->peerhost, "/", $a->peerport, "n";
          die unless defined(my $p = fork);
          close($a), next if $p;
          open STDIN, "<&", $a and open STDOUT, ">&", $a or die "dup: $!";
          close $s and close $a or die "close: $!";
          exec(@ARGV); die "exec @ARGV: $!";



          Usage: tcpsrv host:port cmd



          This will listen on host:port, and anytime a client connects to host:host, it will fork & exec cmd with its stdin and stdout redirected from/to the connection:



          tcpsrv :9999 ls .
          tcpsrv 127.0.0.1:7000 uptime
          tcpsrv [::]:7000 uptime
          tcpsrv 88.109.110.161:2000 'cat > port2000.txt'





          share|improve this answer

























          • Never worked with perl, but I will do the attempt, thanks

            – Martin Ocando Corleone
            Apr 22 at 13:07













          0












          0








          0







          It's a real pity that there's no standard/readily available tool for such basic task, but if you're not on some embedded system and have some scripting language like perl or python available, you can quickly put something together:



          tcpsrv:



          #! /usr/bin/perl
          use strict;
          use IO::Socket::INET6;
          die "usage: $0 host:port cmd args ... n" unless @ARGV >= 2;
          my $h = shift;
          my $s=new IO::Socket::INET6(ReusePort=>1, Listen=>6, LocalAddr=>$h)
          or die "IO::Socket::INET($h): $!";
          warn "listening on ", $s->sockhost, "/", $s->sockport, "n";
          $SIGCHLD = sub use POSIX qw(WNOHANG); 1 while waitpid(-1, WNOHANG) > 0 ;
          while(1)
          my $a = $s->accept or do die "accept: $!" unless $!EINTR; next ;
          warn "connection from ", $a->peerhost, "/", $a->peerport, "n";
          die unless defined(my $p = fork);
          close($a), next if $p;
          open STDIN, "<&", $a and open STDOUT, ">&", $a or die "dup: $!";
          close $s and close $a or die "close: $!";
          exec(@ARGV); die "exec @ARGV: $!";



          Usage: tcpsrv host:port cmd



          This will listen on host:port, and anytime a client connects to host:host, it will fork & exec cmd with its stdin and stdout redirected from/to the connection:



          tcpsrv :9999 ls .
          tcpsrv 127.0.0.1:7000 uptime
          tcpsrv [::]:7000 uptime
          tcpsrv 88.109.110.161:2000 'cat > port2000.txt'





          share|improve this answer















          It's a real pity that there's no standard/readily available tool for such basic task, but if you're not on some embedded system and have some scripting language like perl or python available, you can quickly put something together:



          tcpsrv:



          #! /usr/bin/perl
          use strict;
          use IO::Socket::INET6;
          die "usage: $0 host:port cmd args ... n" unless @ARGV >= 2;
          my $h = shift;
          my $s=new IO::Socket::INET6(ReusePort=>1, Listen=>6, LocalAddr=>$h)
          or die "IO::Socket::INET($h): $!";
          warn "listening on ", $s->sockhost, "/", $s->sockport, "n";
          $SIGCHLD = sub use POSIX qw(WNOHANG); 1 while waitpid(-1, WNOHANG) > 0 ;
          while(1)
          my $a = $s->accept or do die "accept: $!" unless $!EINTR; next ;
          warn "connection from ", $a->peerhost, "/", $a->peerport, "n";
          die unless defined(my $p = fork);
          close($a), next if $p;
          open STDIN, "<&", $a and open STDOUT, ">&", $a or die "dup: $!";
          close $s and close $a or die "close: $!";
          exec(@ARGV); die "exec @ARGV: $!";



          Usage: tcpsrv host:port cmd



          This will listen on host:port, and anytime a client connects to host:host, it will fork & exec cmd with its stdin and stdout redirected from/to the connection:



          tcpsrv :9999 ls .
          tcpsrv 127.0.0.1:7000 uptime
          tcpsrv [::]:7000 uptime
          tcpsrv 88.109.110.161:2000 'cat > port2000.txt'






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Apr 21 at 18:52

























          answered Apr 21 at 17:43









          Uncle BillyUncle Billy

          1,0018




          1,0018












          • Never worked with perl, but I will do the attempt, thanks

            – Martin Ocando Corleone
            Apr 22 at 13:07

















          • Never worked with perl, but I will do the attempt, thanks

            – Martin Ocando Corleone
            Apr 22 at 13:07
















          Never worked with perl, but I will do the attempt, thanks

          – Martin Ocando Corleone
          Apr 22 at 13:07





          Never worked with perl, but I will do the attempt, thanks

          – Martin Ocando Corleone
          Apr 22 at 13:07

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • 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%2funix.stackexchange.com%2fquestions%2f513648%2fhow-to-use-bash-to-create-a-socket-server-and-allow-multiple-clients-in-the-same%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 write a 12-bar blues melodyI-IV-V blues progressionHow to play the bridges in a standard blues progressionHow does Gdim7 fit in C# minor?question on a certain chord progressionMusicology of Melody12 bar blues, spread rhythm: alternative to 6th chord to avoid finger stretchChord progressions/ Root key/ MelodiesHow to put chords (POP-EDM) under a given lead vocal melody (starting from a good knowledge in music theory)Are there “rules” for improvising with the minor pentatonic scale over 12-bar shuffle?Confusion about blues scale and chords

          What if the end-user didn't have the required library?What is setup.py?What is a clean, pythonic way to have multiple constructors in Python?What does Ruby have that Python doesn't, and vice versa?What is the reason for having '//' in Python?How do I create a namespace package in Python?How to package shared objects that python modules depend on?setuptools vs. distutils: why is distutils still a thing?Navigation in Windows 10 vs code not going to virtualenv library when the same library is installed at user levelPython create package for local usePackaging a project that uses multiple python versionsWhy is permission denied on pip install except for when “--user” is included at end of command?

          Why did Thanos need his ship to help him in the battle scene?Which actor plays Thanos in the Avengers mid-credits scene?Are there economic implications portrayed in comics where the buildings and cities are ruined almost daily?Old X-Men comic where team travels to alien world with a ring-like sun that needs recharging?Why does Ego need help sleeping?Is there an objective answer to who “the strongest Avenger” is?How did Banner get unstuck?Why did Thanos get hit?How did Thanos (or anyone) know the Infinity Stones would give him this power?Did Thanos leave Eitri alive for his after-sales service?In Avengers 1, why does Thanos need Loki?