Pipe between sockets

心已入冬 提交于 2020-01-03 10:20:17

问题


I've got a C++ server that acts as a mirror. What gets in gets out to a different socket. Right now, it reads the socket into a buffer and writes it into the other socket. I want to improve the throughput.

I've read stuff about sendfile() and splice(), but it seems limited to "file-to-socket" transfers. Maybe a simple pipe() between sockets would work. What do you recommend?

A portable solution would be perfect, but it's fine if it's Linux-only.


回答1:


You can setup a named pipe in linux. Multiple 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/).




回答2:


I checked nc(netcat) command as mentioned by Ralu in his comment and it works between two sockets when used with pipe :)

I used the below command :


netcat -l 5556 | netcat localhost 5557

I sent data to the port 5556(a python client) set up by the first nc command and made a server(small python code) listening on port 5557.

I could recv data from port 5557



来源:https://stackoverflow.com/questions/7697617/pipe-between-sockets

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!