大网数据广告活动
服务器运维问答

socat forwarding to multiple addresses

· 52CE 我爱测

I have a single incoming video stream, and I'd like to set up multiple processes to handle it, each running at its own address. After some reading it seems socat is one way to do this socat TCP4-LISTEN:1934,fork,reuseaddr TCP4:so…

问题原文

原帖链接 · Shukri Adams · CC BY-SA 3.0

I have a single incoming video stream, and I'd like to set up multiple processes to handle it, each running at its own address. After some reading it seems socat is one way to do this

socat TCP4-LISTEN:1934,fork,reuseaddr TCP4:someaddress:1935 

This forwards everything to the target address, but it lets me bind one target only. Is there a way to bind multiple target addresses with socat? If I try multiple individual binds I get an "address already in use" error on subsequent binds. I'm not forced to use socat, anything that lets me copy my incoming stream is good, if anyone knows a better approach. Thanks.

已采纳解答

原帖链接 · Patrick Mevzek · CC BY-SA 3.0

Based on my earlier comments, I have just tested this solution[1] and it works as expected, if I understood your needs:

socat -u tcp4-listen:1934 - | tee >(socat - tcp4:127.0.0.1:1935) >(socat - tcp4:127.0.0.1:1936) > /dev/null

There must be processes already listening on 1935 and 1936 already before launching this otherwise the socat on the right will complain.

This is still a very brittle solution. I would advise trying alternative routes, like a temporary caching file or a pipe maybe.

[1] like that:

  • nc -l 127.0.0.1 1935 in a shell
  • nc -l 127.0.0.1 1936 in another shell
  • the command above in the third shell
  • and then in a fourth one: echo "foobar" | nc 127.0.0.1 1934
  • and I do see "foobar" in output in first and second shell.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-02-02)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。