Pipe between sockets

I have a C ++ server that acts like a mirror. What receives goes to another socket. Right now, it reads the socket into the buffer and writes it to another socket. I want to improve throughput.

I read stuff about sendfile() and splice() , but it seems to carry over to file-to-socket transmission. A simple pipe() between sockets might work. What do you recommend?

A portable solution would be ideal, but it's great if it's Linux-only.

+6
source share
2 answers

You can configure the named pipe in linux. Several processes could read / write from this. Check out this link: http://www.cs.fredonia.edu/zubairi/s2k2/csit431/more_pipes.html .

Also, as mentioned above, using netcat should do the trick (http://netcat.sourceforge.net/).

+4
source

I checked the nc(netcat) command as pointed out in Ralu in my comment and it works between two sockets when used with pipe :)

I used the following command:

 netcat -l 5556 | netcat localhost 5557
netcat -l 5556 | netcat localhost 5557 
I sent the data to port 5556 (the python client) configured by the first nc command, and made a server (small python code) listening on port 5557.

I could get data from port 5557

0
source

Source: https://habr.com/ru/post/898891/


All Articles