Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This is question is somehow related to How is it called when listening(connecting) two sockets and exchanging data between them?

In the test setup I have three terminal windows open I run in

Term1: "nc -l 55545"
Term2: "nc -l 55546"
Term3: "socat tcp:localhost:55545 tcp:localhost:55546"

Input to Term1 now appears in Term2 and input to Term2 appears in Term1.

This is the desired behavior. How can I achieve this behavior by only using nc?

When I run in

Term3: "nc localhost 55545 | nc localhost 55546"

then Input to Term1 appears in Term2 but input to Term2 appears in Term3. How can I make the pipe bidirectional? If possible without temporary files.

share|improve this question
add comment

1 Answer

This comes straight from the Wikipedia page on netcat. In Term3, you would run:

mkfifo backpipe
nc localhost 55545 0<backpipe | nc localhost 55546 1>backpipe

This does pretty much exactly what you want. It uses a FIFO to get output from the left-hand side back into the right-hand side. It's not, strictly speaking, a temporary file -- a FIFO is a named pipe between two processes.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.