Q:

Redirect STDIN to socket and socket to STDOUT

I am trying to develop a simple command-line client to the server. After I connect to the server and setup everything correctly I want to redirect STDIN to the socket connected to the server and the same socket to STDOUT. I want to achieve behavior similar to the of nc tool.
The most simple solution would be use select() and use read()/write() to pass data from STDIN to the socket and from the socket to STDOUT.
Is there any other simpler way to somehow connect socket to to the STDIN/STDOUT? I thought about using dup2() system call. However, I am not sure how to make it work.
Thanks.

A:

On Linux you can use splice(2) to move data between file descriptors at the kernel level. Though, you would still have to use select(2) (or equivalent) to handle the two directions in parallel or alternatively use two threads.

