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

问题描述

我写一个运行在端口4900。在某些情况下,当人在路由器后面,该端口是不是从Internet访问的自定义P2P程序。

I am writing a custom p2p program that runs on port 4900. In some cases when the person is behind a router, this port is not accessible from the internet.

有没有能够从互联网访问端口的自动方式。我真的不知道如何等P2P应用程序的工作。

Is there an automatic way of enabling the access to the port from the internet. I am not really sure of how other p2p applications work.

任何人都可以请扔一些轻的呢?

Can anyone please throw some light on this?

推荐答案

简而言之P2P连接。假设我们在谈论UDP这里。还可以应用于下面的步骤TCP进行一些调整。

P2P connectivity in a nutshell. Assume we're talking about UDP here. The steps below can also be applied to TCP with some adjustments.

  1. 枚举所有本地IP地址(通常只有1人)。创建一个UDP套接字在一个给定的端口号**每个适配器的IP地址。

  1. Enumerate all your local IP addresses (usually only 1). Create a UDP socket on a given port number** for each adapter with an IP address.

有关在步骤1中创建的每个插座,请联系STUN或TURN服务器的同一个插座发现您的外部IP地址和发现什么内部端口号映射到NAT外(它并不总是相同端口值)。也就是说,你的本地地址192.168.1.2:4900可能128.11.12.13:8888到外面的世界。并使用相同的本地端口其他IP地址时一些NAT之后并不总是使用相同的端口映射。 TURN还将为您提供一个中继地址。您也可以使用UPnP来获得一个端口映射,从你的路由器直接解决,如果它支持该协议。

For each socket created in step 1, contact a STUN or TURN server with that same socket to discover your external IP address and to discover what the internal port number maps to outside of the NAT (it's not always the same port value). That is, your local address 192.168.1.2:4900 might be 128.11.12.13:8888 to the outside world. And some NATs don't always use the same port mapping when using the same local port to other IP addresses. TURN will also provide you a "relay address". You can also use UPNP to get a port mapped address directly from your router, if it supports that protocol.

通过交会服务(SIP,XMPP,即时消息,Web服务,电子邮件,杯具的字符串),您的地址候选名单发布到服务或发送通知给其他客户,说:哎,我想与您联系。这个消息包括收集在步骤1和2中的所有候选地址(IP和端口对)。

Through a rendezvous service (SIP, XMPP, instant message, web service, email, cups with strings), publish your address candidate list to a service or send a notification to the other client that says, "hey, I want to connect with you". This message includes all the "address candidates" (ip and port pairs) collected in steps 1 and 2.

远程客户端,在接收到邀请进行连接,进行步骤1和2以上为好。然后发回自己的候选人名单通过,他收到的邀请的候选名单相同的信道。

The remote client, upon receiving the invite to connect, performs step 1 and 2 above as well. Then sends back his candidate list through the same channel that he received the inviter's candidate list on.

孔冲孔步骤。两个客户端,开始通过UDP发送测试信息到对方的地址候选人并聆听他们结束了相同的消息。每当收到的消息,回复回到它原来的地址。最终,客户会发现,他们有一对,他们可以可靠地发送数据报太大的地址。通常情况下,一个端点使得其上的地址对(插座)的最终决定与沟通,该协议有利于这个端点告诉另一个端点这一决定。

Hole punching step. Both clients, start sending test messages over UDP to the other side's address candidates and listening for the same messages on their end. Whenever a messages is received, reply back to the address from which it came. Eventually, the clients will discover that they have a pair of addresses that they can reliably send datagrams too. Typically, one endpoint makes the final decision on which address pair (sockets) to communicate with and the protocol facilitates this endpoint telling the other endpoint this decision.

** - 通常最好不要依赖一个众所周知的端口的P2P客户端上。因为相同的NAT或防火墙的后面两个客户将不太可能能够使用你的软件在同一时间。

**- usually best to not to rely on a well known port for P2P clients. Because two clients behind the same NAT or firewall would not likely be able to use your software at the same time.

下面是一些技术的快速总结探索。

Here is a quick summary of some technologies to explore.

STUN - 是一个简单的服务器和协议的NAT /路由后面的客户端去发现他们的外部IP地址和端口映射是。

STUN - Is a simple server and protocol for clients behind a NAT/route to discover what their external IP and port mappings are.

开启是一个扩展STUN,但支持中继的P2P连接方案,其中防火墙和NAT prevent直接连接。

TURN is an expansion to STUN, but supports relaying for P2P connectivity scenarios where firewalls and NATs prevent direct connections.

ICE 是一组由STUN和TURN用于建立P2P连接的步骤。 ICE是一个正式的协议,用于上述1-5步骤。二一套优秀的冰滑梯是这里和href="http://www.jdrosen.net/uploads/1/5/0/0/15008848/ice-ietf-tutorial2.pptx">这里

ICE is a set of steps by which STUN and TURN are used for setting up a P2P connection. ICE is a formal protocol for steps 1-5 above. Two excellent set of slides on ICE are here and here.

实现WebRTC 是的ICE标准的一个变种,以及与STUN和TURN化妆P2P会话参考图书馆。

WebRTC is a variant of the ICE standard as well as a reference library for make P2P sessions with STUN and TURN.

UPNP +互联网网关设备协议 - 一些路由器支持此为主机自动获取端口映射

UPNP + Internet Gateway Device Protocol - Some routers support this for hosts to automatically obtain port mappings.

libnice 是为Linux的开源C库(和可能工作在Windows上)实现ICE。

libnice is an open source C library for Linux (and might work on windows) that implements ICE.

libjingle 是从谷歌的另一个ICE实现(C ++)。对于Windows和Linux。

libjingle is another ICE implementation (in C++) from Google. For Windows and Linux.

PJNATH 是的套装编码库。这是一个很好的实现了ICE堆栈(C code),并已经被移植到了很多平台上。 (Windows,Linux和Mac的,的iOS,Symbian和Android的很快)。

PJNATH is a library within the PJSIP suite of coding libraries. It is a good implementation of an ICE stack (C code) and has been ported to a lot of platforms. (Windows, Linux, Mac, iOS, Symbian, and soon Android).

最后,我有一个赤裸裸的插件供您使用我STUN服务器code碱基

And finally, I have a blatant plug for you to use my STUN server code base.

这篇关于编程P2P应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 10:33