Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
netcat-like stdio to tcp "proxy"? [SOLVED]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
Sadako
Advocate
Advocate


Joined: 05 Aug 2004
Posts: 3789
Location: sleeping in the bathtub

PostPosted: Thu Jun 01, 2017 8:53 pm    Post subject: netcat-like stdio to tcp "proxy"? [SOLVED] Reply with quote

I'm playing around with http requests from shell, and I have a working script with both bash's networking and by using netcat/socat with named pipes, but, both nc and socat terminate after one http request and response...

I`m looking for a solution where "proxy" I'm using will keep running and accept new connections after the first one, something neither nc nor socat seems to support unless binding to an ip address.

Running nc or socat within a while loop would do the trick, but I'm looking for something "cleaner", or more efficient, and ideas?

In case it's unclear, this is what I'm using;
Code:
nc 127.0.0.1 8080 < nc_in > nc_out
with nc_in and nc_out two named pipes or fifos.

Thanks.
_________________
"You have to invite me in"


Last edited by Sadako on Sat Jun 03, 2017 3:52 pm; edited 1 time in total
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 5912

PostPosted: Fri Jun 02, 2017 6:11 pm    Post subject: Reply with quote

net-misc/s6-networking?
Back to top
View user's profile Send private message
szatox
Veteran
Veteran


Joined: 27 Aug 2013
Posts: 1762

PostPosted: Fri Jun 02, 2017 6:44 pm    Post subject: Reply with quote

Server-side nc:
Quote:
--continuous Enable continuous accepting of connections in listen mode, like inetd. Must be used with --exec to specify the command to run locally (try 'nc6 --continuous --exec cat -l -p <port>' to make a simple echo server).


If you want to have many sources use a single netcat client, you can have it read from a fifo. Fifo terminates when the last program on either end exits, and it can be used by many programs at the same time. This means, you can use some idling process to keep the fifo open (say '( read; ) > fifo' ) and then you can even write with echo >fifo and it will not terminate connection even though it exits instantly.
Still, even though sharing a single connection is possible, I'd rather go with one instance of nc/curl/anything per task.
Back to top
View user's profile Send private message
Sadako
Advocate
Advocate


Joined: 05 Aug 2004
Posts: 3789
Location: sleeping in the bathtub

PostPosted: Sat Jun 03, 2017 3:52 pm    Post subject: Reply with quote

Thank you both very much for your responses, as it turns out I was looking at this wrong, the actual problem was that the http server was closing the connection after serving a single request, which is why netcat was exiting.

I was just testing with busybox httpd, which doesn't support http keep-alive (but I actually knew that, so I have no excuse really...).

Testing with lighttpd and adding the "Connection: keep-alive" header, it just works exactly as I wanted.

szatox wrote:
If you want to have many sources use a single netcat client, you can have it read from a fifo. Fifo terminates when the last program on either end exits, and it can be used by many programs at the same time. This means, you can use some idling process to keep the fifo open (say '( read; ) > fifo' ) and then you can even write with echo >fifo and it will not terminate connection even though it exits instantly.
Yeah, what I was doing was opening a file descriptor to the named pipes I had redirected netcat's stdin and stdout to in the shell script.
Quote:
Still, even though sharing a single connection is possible, I'd rather go with one instance of nc/curl/anything per task.
Generally, I completely agree on this, but there are always exceptions. ;)

Anyways, ty both again.
_________________
"You have to invite me in"
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum