直接P2P连接 [英] Direct P2P connection

查看:103
本文介绍了直接P2P连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此主题类似于此线程

我对网络编程这个话题还很陌生,除了在单个本地计算机上进行基本的TCP/UDP之外,什么都没有做.现在,我正在开发需要P2P网络支持的应用程序.更具体地说,我将需要该应用程序在Internet上进行连接和通信,最好不要使用服务器来进行客户端之间的配对.

我知道并假设几乎所有用户都在路由器后面,这使该过程变得复杂,因为两个客户端都无法初始化与另一个客户端的直接连接.

我知道UPnP是允许端口转发而无需用户手动配置的选项,但是到目前为止,这不是一个选项.他们有什么方法可以实现我的目标,还是我需要该服务器?

解决方案

您将需要服务器来交换IP地址等.正如另一个线程从字面上指出的那样,保证连接的唯一方法是通过服务器进行代理.大多数情况下,大多数对等系统都使用 UPnP NAT打孔(此方法需要服务器中继端口信息,并且仅与UDP一起使用)来建立连接.

NAT打孔的工作原理是两个客户端都建立与服务器的连接,然后两个客户端都尝试直接连接到另一个已中继到另一个的端口.大多数UDP NAT会在短时间内记住IP地址和端口,因此尽管数据从未到达另一端(这与UDP无关),但其他客户端将稍后尝试尝试将该报告作为NAT连接会得到答复.

This topic resembles this thread

I'm rather new to the topic of network programming, never having done anything but basic TCP/UDP on a single local machine. Now I'm developing an application that will need P2P network support. More specifically I will need the application to connnect and communicate across the internet preferably without the use of a server to do the matchmaking between the clients.

I'm aware and assuming that almost all users are behind a router which complicates the process since neither clients will be able to initialize a direct connection to the other.

I know UPnP is an option to allow port forwarding without having the users configure this manually, but as of now this is not an option. Is they any way to achieve my goal or will I need that server?

解决方案

You'll need a server to exchange IP address and such. As the other thread literally points out, the only way of guaranteeing a connection is to proxy through a server. Most peer to peer systems use UPnP and NAT Hole Punching (this method needs a server relaying port information and only works with UDP) to establish a connection in most cases.

NAT Hole Punching works by both clients establishing a connection to a server, then the both try to connect directly to a port that the other has relayed to the other. Most UDP NAT remember the IP address and port for a short time, so although the data never made it to the other end (not that this matters with UDP) the other client will try to connect a few moments later to that report as the NAT would expect the reply.

这篇关于直接P2P连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆