背景
1.下载
http://www.dest-unreach.org/socat/download
本人这里使用的版本是socat-1.7.3.4.tar.gz,并非最新的包。
2.解压
//解压到当前目录
$ tar -xvf socat-1.7.3.4.tar.gz
//进入解压后的目录
$ cd socat-1.7.3.4
3.安装
//编译hisi600
./configure --host=x86_64 CC=arm-hisiv600-linux-gcc
make -j8
make insatll
//编译rk
./configure --host=x86_64 CC=aarch64-linux-gcc
make -j8
make insatll
//编译到linux 这里生成的是共享库 不是可执行程序 比较奇怪
./configure
make -j8
make insatll
生成了三个可执行程序:socat,procan,filan
4.执行命令
//查看版本号
$ ./socat -V
socat by Gerhard Rieger and contributors - see www.dest-unreach.org
socat version 1.7.3.4 on Nov 6 2021 16:28:06
running on Linux version #100~18.04.1-Ubuntu SMP Wed Sep 29 10:59:42 UTC 2021, release 5.4.0-89-generic, machine x86_64
//测试网络联通性 本机打开两个终端,分别建立一个TCP服务端和客服端,任意从一端输入,查看另一端是否有收到消息
//terminal 1建立8989端口 短横杆 - 表示当前输入输出端
$ ./socat - TCP-LISTEN:8989
ss
Ilove
//terminal 2连接到本机8989端口
$ ./socat - TCP:localhost:8989
ss
Ilove
//端口转发
//建立一个服务器中转站 8989,将所有接收到的数据转发到另外一个本地端口9900
$ ./socat TCP-LISTEN:8989,fork,reuseaddr TCP:localhost:9900
//发送端 发到8989端口
$ ./socat - TCP:localhost:8989
//接收端 监听9900端口
$ ./socat TCP-LISTEN:9900 -
参考:[1] https://zhuanlan.zhihu.com/p/347722248