如何在对等 2 对等设置中连接两个套接字连接
我还不确定这是否可能,并且我正在寻找可以找到更多信息的地方。这主要是作为练习来完成的,但我想看看我是否可以将其实现为一种解决方案,以在两个人之间以最小的麻烦共享非常大的文件(并且我意识到可能存在一些类似的解决方案,但我仍然想要尝试写一个)。
基本设置如下: 我正在考虑使用侦听端口 XYZ 的程序配置服务器。我有两个示例用户(A 和 B)。用户“A”想要与用户“B”共享文件。 “A”转到他的本地客户端并将一些信息推送到服务器。他取回了一个密钥,可以按照自己喜欢的方式发送给用户“B”(而不是发布或广播该位置)。用户“B”获得密钥,并将其放入他的客户端。他的客户端访问服务器并获取有关如何连接到用户“A”的计算机进行文件传输的信息。
现在,对于可以直接通过套接字连接的机器来说,这已经足够简单了,但我假设用户 A 和 B 位于完全不同的网络上,位于不同的公共 IP(普通互联网用户)后面。所以我想知道的是,我可以让用户“A”和用户“B”监视服务器上的状态,并且当明显需要共享文件时,使用服务器作为桥梁以某种方式连接两者.. . 进行握手,然后创建一个新套接字,或者以某种方式加入连接到服务器的套接字?整个事情的警告是,我希望带宽不要沿着服务器传输(或者我可以直接启动到服务器的连接),而是在两台机器之间直接进行点对点传输,仅使用服务器进行协商一个连接。
但我不知道在哪里可以找到有关此的信息,或者是否可能:)
我的偏好是使用 Java。
I'm not yet sure if this is possible, and I'm looking for where more information might be found. It's mostly being done as an exercise, but I want to see if I can implement this at all as a solution to sharing very large files with minimal hassle between two individuals (and I realize some solutions might exist that are similar, but I still want to try and write one).
Basic setup is as follows:
I'm figuring on configuring a server with a program that listens on port XYZ. I'd have two example users (A and B). User "A" wants to share a file with user "B". "A" goes to his local client and pushes some information to the server. He gets back a key that he can send to user "B" however he likes (instead of publishing or broadcasting the location). User "B" gets the key, puts it into his client. His client goes to the server and gets the information on how to connect to User "A"s machine for the file transfer.
Now, this is simple enough with machines that can connect via a socket directly, but I'm assuming user A and B are on completely different networks, behind different public IP's (normal internet users). So what I wondered is, can I have user "A" and user "B" monitor a status on the server, and when it's apparent that it's time to share the file, use the server as a bridge to connect the two somehow ... communicate a handshake and then either a new socket, or somehow join sockets connected to the server? The caveat in this whole thing is that I'd like the bandwidth not to be transferred along the server (or I could just initiate direct connections to the server), but directly peer to peer between the two machines, using the server only to negotiate a connection.
But I've no idea where to look on information about this, or if it's possible :)
My preference is to use Java.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了直接连接两个套接字而不使用服务器作为代理,必须具有作为端点直接命中的能力。
我想不出任何设施可以协商 NAT 或 PAT 后面的两个连接,然后退出环路而使另外两个连接保持连接。
如果您可以在设计规范中构建这样的设计规范:客户端必须打开各自的监听端口并将其映射到它们用于路由的任何系统中,那么这是可能的。
In order to directly connect the two sockets without using the server as a broker, one will have to have the ability to be hit directly as an endpoint.
I can think of no facility that can negotiate two connections behind a NAT or PAT and then drop out of the loop leaving the other two connected.
If you can build into the design spec that the clients must have their respective listen ports open and mapped in whatever system they use to route then it would be possible.