使用中间主机建立 TCP Socket 连接
我需要在Java中的两个主机(例如host1和host2)之间建立套接字连接(TCP)。但由于防火墙的原因,我似乎无法做到这一点。虽然还有第三个主机(例如 host3),可以从 host1 和 host2 访问,但我认为可以用作此连接的中间设备。
所以基本上,我想从host1(客户端)发送请求到host3,这会将我的请求重定向到host2(服务器)。
您能否告诉我如何实现这一目标?
提前致谢!
I need to establish a Socket connection (TCP) between two hosts (say host1 and host2) in Java. But looks like I can't do that because of a firewall. Though there's a third host (say host3) which is accessible from both host1 and host2 and I think can be used as an intermediate for this connection.
So basically, I want to send a request from host1 (client) to host3, which redirects my request to host2 (server).
Could you please let me know how can this be achieved?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以建立 SSH 隧道
,然后在端口 4321 上从主机 1 连接到主机 3。这实际上会重定向到主机 2 上的端口 6523。
类似的选项可能是让 ssh 提供 SOCKS 服务器。
然后使用
curl
而不是wget
。然后你可以做
(未经测试,
--socks4a
和--socks5
也可以是一个选项......)这个
ssh
命令创建一个本地 SOCKS 服务器将连接尝试通过隧道传送到 ssh 服务器,然后由 ssh 服务器执行它们。You could establish a SSH tunnel with
and then connect from host1 to host3 on port 4321. This effectively gets redirected to port 6523 on host2.
A similiar option could be to have
ssh
provide a SOCKS server.and then use
curl
instead ofwget
.Then you can do
(untested,
--socks4a
and--socks5
could be an option as well...)This
ssh
command creates a SOCKS server locally which tunnels the connection attempts to the ssh server, which in turn executes them.