技术领域technical field
本发明实施例涉及网络通信技术领域,尤其涉及一种对等网络连接方法及装置。The embodiments of the present invention relate to the technical field of network communication, and in particular, to a peer-to-peer network connection method and device.
背景技术Background technique
为了提高网络直播或点播过程中资源播放的流畅性,传统的解决方案针对资源服务器进行了改进。但改进方案的网络架构中只有资源服务器在向用户提供数据,即使花费高昂的成本进行资源服务器的升级,还是无法满足日益增多的用户需求。In order to improve the fluency of resource playback during webcast or on-demand, traditional solutions have been improved for resource servers. However, in the network architecture of the improved solution, only the resource server is providing data to users. Even if the resource server is upgraded at a high cost, it still cannot meet the increasing user needs.
为了弥补上述方案的缺陷,现有技术的另一种方案中采用P2P对等网络连接方式,请求端和服务端建立对等连接后可进行资源的共享,这样,请求端就无需再持续向资源服务器请求数据了,从而分担了资源服务器的一部分压力。但是,现有技术中P2P网络系统中通常采用Webrtc连接协议进行对等连接,这种连接协议由于网络稳定性、路由器支持限制等原因发生连接中断或连接失败的情况较多,分担资源服务器压力的效果并不理想。In order to make up for the defects of the above-mentioned solutions, another solution in the prior art adopts a P2P peer-to-peer network connection mode, and the requester and the server can share resources after establishing a peer-to-peer connection. The server requests data, thus sharing part of the pressure on the resource server. However, in the P2P network system in the prior art, the Webrtc connection protocol is usually used for peer-to-peer connections. Due to network stability, router support restrictions, and other reasons, this connection protocol often causes connection interruption or connection failure. The effect is not ideal.
发明内容Contents of the invention
本发明实施例提供一种对等网络连接方法及装置,用以解决现有技术中P2P网络系统中请求端和服务端连接中断或连接失败概率较高的问题。Embodiments of the present invention provide a peer-to-peer network connection method and device to solve the problem of high probability of connection interruption or connection failure between a requester and a server in a P2P network system in the prior art.
本发明实施例提供一种对等网络连接方法,包括:An embodiment of the present invention provides a peer-to-peer network connection method, including:
请求端获取P2P服务器提供的包含所述请求端所需资源的服务端的端口信息,所述端口信息包括服务端的私有端口映射的路由器的公网端口;The requesting end obtains the port information of the service end that contains the resources required by the requesting end provided by the P2P server, and the port information includes the public network port of the router mapped to the private port of the service end;
所述请求端向所述路由器的公网端口发送对等网络连接请求,由所述路由器根据所述路由器的公网端口映射的所述服务端的私有端口将所述对等网络连接请求转发至所述服务端;The requesting end sends a peer-to-peer network connection request to the public network port of the router, and the router forwards the peer-to-peer network connection request to the private port of the server according to the public network port mapping of the router. the server side;
所述请求端在接收到所述路由器转发的所述服务端响应所述对等网络连接请求的应答消息后,建立与所述服务端的对等网络连接。The requesting end establishes a peer-to-peer network connection with the server after receiving a response message from the server forwarded by the router in response to the peer-to-peer network connection request.
本发明实施例提供一种对等网络连接方法,包括:An embodiment of the present invention provides a peer-to-peer network connection method, including:
服务端根据其私有端口映射的路由器的公网端口生成端口信息;The server generates port information according to the public network port of the router mapped to its private port;
所述服务端将资源信息及端口信息上报至P2P服务器;The server reports resource information and port information to the P2P server;
所述服务端在接收到请求端发送的对等网络连接请求时,将响应所述对等网络连接请求的应答消息通过所述服务端的私有端口映射的所述路由器的公网端口转发至所述请求端,并建立与所述请求端的对等网络连接;When the server receives the peer-to-peer network connection request sent by the requesting end, it forwards the response message in response to the peer-to-peer network connection request to the A requesting end, and establishing a peer-to-peer network connection with the requesting end;
其中,所述对等网络连接请求由所述请求端在获取P2P服务器提供的包含所述请求端所需资源的服务端的端口信息后,根据所述端口信息包括的服务端的私有端口映射的路由器的公网端口,向所述路由器的公网端口发送,并由所述路由器根据所述路由器的公网端口映射的所述服务端的私有端口转发至所述服务端。Wherein, the peer-to-peer network connection request is obtained by the requesting end after obtaining the port information of the server end that contains the resources required by the requesting end provided by the P2P server, and according to the private port mapping of the server end included in the port information. The public network port is sent to the public network port of the router, and forwarded to the server by the private port of the server mapped by the router according to the public network port of the router.
本发明实施例提供一种对等网络连接方法,包括:An embodiment of the present invention provides a peer-to-peer network connection method, including:
路由器接收请求端发送的对等网络连接请求,所述对等网络连接请求由所述请求端在获取P2P服务器提供的包含所述请求端所需资源的服务端的端口信息后,根据所述端口信息包括的服务端的私有端口映射的路由器的公网端口,向所述路由器的公网端口发送的;The router receives the peer-to-peer network connection request sent by the requesting end. The peer-to-peer network connection request is obtained by the requesting end after obtaining the port information of the service end provided by the P2P server that contains the resources required by the requesting end, according to the port information. The public network port of the router included in the private port mapping of the server is sent to the public network port of the router;
所述路由器根据所述路由器的公网端口映射的所述服务端的私有端口将所述对等网络连接请求转发至所述服务端;The router forwards the peer-to-peer network connection request to the server according to the private port of the server mapped to the public network port of the router;
所述路由器接收所述服务端发送的响应所述请求端发送的对等网络连接请求的应答消息,并将所述应答消息转发至所述请求端,以便于所述请求端在接收到所述路由器转发的所述服务端的应答消息后,建立与所述服务端的对等网络连接。The router receives the reply message sent by the server in response to the peer-to-peer network connection request sent by the requester, and forwards the reply message to the requester, so that the requester receives the After forwarding the reply message of the server, the router establishes a peer-to-peer network connection with the server.
本发明实施例提供一种对等网络连接装置,包括:An embodiment of the present invention provides a peer-to-peer network connection device, including:
信息获取模块,用于获取P2P服务器提供的包含所述请求端所需资源的服务端的端口信息,所述端口信息包括服务端的私有端口映射的路由器的公网端口;An information acquisition module, configured to acquire port information of a server provided by a P2P server that includes resources required by the requester, where the port information includes a public network port of a router mapped to a private port of the server;
连接请求模块,用于向所述路由器的公网端口发送对等网络连接请求,由所述路由器根据所述路由器的公网端口映射的所述服务端的私有端口将所述对等网络连接请求转发至所述服务端;A connection request module, configured to send a peer-to-peer network connection request to the public network port of the router, and the router forwards the peer-to-peer network connection request according to the private port of the server mapped to the public network port of the router to the server;
连接建立模块,用于在接收到所述路由器转发的所述服务端响应所述对等网络连接请求的应答消息后,建立与所述服务端的对等网络连接。A connection establishing module, configured to establish a peer-to-peer network connection with the server after receiving a response message forwarded by the router in response to the peer-to-peer network connection request from the server.
本发明实施例提供一种对等网络连接装置,包括:An embodiment of the present invention provides a peer-to-peer network connection device, including:
信息生成模块,用于根据其私有端口映射的路由器的公网端口生成端口信息;The information generation module is used to generate port information according to the public network port of the router mapped by its private port;
信息上报模块,用于将资源信息及端口信息上报至P2P服务器;The information reporting module is used to report resource information and port information to the P2P server;
响应模块,用于在接收到请求端发送的对等网络连接请求时,将响应所述对等网络连接请求的应答消息通过所述服务端的私有端口映射的所述路由器的公网端口转发至所述请求端,并建立与所述请求端的对等网络连接;The response module is configured to, when receiving the peer-to-peer network connection request sent by the requesting end, forward the response message in response to the peer-to-peer network connection request to the public network port of the router mapped to the private port of the server to the the requesting end, and establish a peer-to-peer network connection with the requesting end;
其中,所述对等网络连接请求由所述请求端在获取P2P服务器提供的包含所述请求端所需资源的服务端的端口信息后,根据所述端口信息包括的服务端的私有端口映射的路由器的公网端口,向所述路由器的公网端口发送,并由所述路由器根据所述路由器的公网端口映射的所述服务端的私有端口转发至所述服务端。Wherein, the peer-to-peer network connection request is obtained by the requesting end after obtaining the port information of the server end that contains the resources required by the requesting end provided by the P2P server, and according to the private port mapping of the server end included in the port information. The public network port is sent to the public network port of the router, and forwarded to the server by the private port of the server mapped by the router according to the public network port of the router.
本发明实施例提供一种对等网络连接装置,包括:An embodiment of the present invention provides a peer-to-peer network connection device, including:
请求接收模块,用于接收请求端发送的对等网络连接请求,所述对等网络连接请求由所述请求端在获取P2P服务器提供的包含所述请求端所需资源的服务端的端口信息后,根据所述端口信息包括的服务端的私有端口映射的路由器的公网端口,向所述路由器的公网端口发送的;The request receiving module is used to receive the peer-to-peer network connection request sent by the requesting end, and the peering network connection request is obtained by the requesting end after obtaining the port information of the server that contains the resources required by the requesting end provided by the P2P server, According to the public network port of the router mapped to the private port of the server included in the port information, it is sent to the public network port of the router;
转发模块,用于根据所述路由器的公网端口映射的所述服务端的私有端口将所述对等网络连接请求转发至所述服务端;A forwarding module, configured to forward the peer-to-peer network connection request to the server according to the private port of the server mapped to the public network port of the router;
所述转发模块,还用于接收所述服务端发送的响应所述请求端发送的对等网络连接请求的应答消息,并将所述应答消息转发至所述请求端,以便于所述请求端在接收到所述路由器转发的所述服务端的应答消息后,建立与所述服务端的对等网络连接。The forwarding module is further configured to receive a response message sent by the server in response to the peer-to-peer network connection request sent by the requesting end, and forward the response message to the requesting end, so that the requesting end may After receiving the response message of the server forwarded by the router, establish a peer-to-peer network connection with the server.
本发明实施例提供的对等网络连接方法及装置,通过将请求端的连接请求经路由器的公网端口转发至服务端的私有端口,解决了现有技术中由于路由器限制等原因造成的请求端无法实现与私有网络中的服务端建立对等网络连接的问题。为现有的P2P网络系统提供了一种补充连接方式,以避免因现有连接方式的局限性造成连接失败率或连接中断率过高的问题,从而提高P2P网络系统分担资源服务器压力的能力。The peer-to-peer network connection method and device provided by the embodiment of the present invention, by forwarding the connection request of the requesting end to the private port of the server through the public network port of the router, solves the problem that the requesting end cannot be realized due to router restrictions and other reasons in the prior art. Problems establishing a peer-to-peer network connection with a server in a private network. It provides a supplementary connection method for the existing P2P network system to avoid the problem of high connection failure rate or connection interruption rate caused by the limitations of the existing connection method, thereby improving the ability of the P2P network system to share the pressure on resource servers.
附图说明Description of drawings
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作一简单地介绍,显而易见地,下面描述中的附图是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings that need to be used in the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description These are some embodiments of the present invention. Those skilled in the art can also obtain other drawings based on these drawings without creative work.
图1为本发明对等网络连接方法流程图;Fig. 1 is the flowchart of the peer-to-peer network connection method of the present invention;
图2为本发明对等网络连接方法实施例流程图;Fig. 2 is a flowchart of an embodiment of a peer-to-peer network connection method in the present invention;
图3为本发明对等网络连接方法流程图;Fig. 3 is a flow chart of the peer-to-peer network connection method of the present invention;
图4为本发明对等网络连接方法流程图;Fig. 4 is a flowchart of the peer-to-peer network connection method of the present invention;
图5为本发明对等网络连接装置的结构示意图;5 is a schematic structural diagram of a peer-to-peer network connection device of the present invention;
图6为本发明对等网络连接装置的实施例结构示意图;6 is a schematic structural diagram of an embodiment of a peer-to-peer network connection device of the present invention;
图7为本发明对等网络连接装置的结构示意图;7 is a schematic structural diagram of a peer-to-peer network connection device of the present invention;
图8为本发明对等网络连接装置的结构示意图。FIG. 8 is a schematic structural diagram of a peer-to-peer network connection device according to the present invention.
具体实施方式detailed description
为使本发明实施例的目的、技术方案和优点更加清楚,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments It is a part of embodiments of the present invention, but not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by persons of ordinary skill in the art without creative efforts fall within the protection scope of the present invention.
本发明实施例提供的对等网络连接方法及装置,可应用于网络直播/点播场景中。现有技术中,当用户通过HTML5网页端中的播放器(请求端)发起视频播放请求时,通常采用Webrtc协议与服务端建立对等网络连接,当请求端向P2P服务器发起与服务端的连接请求后,P2P服务器将服务端对应的端口地址返回给请求端,继而请求端根据服务端的端口地址与服务端建立连接。但是,WERTC协议只适用于服务端的端口地址为公网端口的情况,基于Webrtc协议,请求端与服务端仅能通过直接寻址的方式建立连接。因此,当服务端处于私网中时,请求端无法通过Webrtc协议建立与服务端的连接,直播/点播资源也就无法在请求端和服务端之间实现共享,这种情况下,请求端只能向资源服务器请求数据,服务端无法发挥分担资源服务器压力的作用。The peer-to-peer network connection method and device provided by the embodiments of the present invention can be applied to network live broadcast/on-demand scenarios. In the prior art, when the user initiates a video playback request through the player (request end) in the HTML5 web page, the Webrtc protocol is usually used to establish a peer-to-peer network connection with the server, and when the request end initiates a connection request with the server to the P2P server Afterwards, the P2P server returns the port address corresponding to the server to the requesting end, and then the requesting end establishes a connection with the server according to the port address of the server. However, the WERTC protocol is only applicable to the case where the port address of the server is a public network port. Based on the Webrtc protocol, the requester and the server can only establish a connection through direct addressing. Therefore, when the server is in a private network, the requester cannot establish a connection with the server through the Webrtc protocol, and live/on-demand resources cannot be shared between the requester and the server. In this case, the requester can only When requesting data from the resource server, the server cannot play the role of sharing the pressure on the resource server.
本发明实施例提供的对等网络连接方法及装置,正是要改变Webrtc协议存在的上述缺陷,提供补充的连接方案。请求端将连接请求通过路由器的公网端口转发至服务端的私有端口,从而,可在服务端处于私网的场景下,实现请求端与服务端的对等连接。The peer-to-peer network connection method and device provided by the embodiments of the present invention are intended to change the above-mentioned defects of the Webrtc protocol and provide a supplementary connection solution. The requester forwards the connection request to the private port of the server through the public network port of the router, so that the peer-to-peer connection between the requester and the server can be realized when the server is in a private network.
另外,本发明实施例提供的对等网络连接方法及装置,还可应用于其它需要与私有网络中的终端建立网络连接的场景,本发明对此不作限定。In addition, the peer-to-peer network connection method and device provided in the embodiments of the present invention can also be applied to other scenarios where a network connection needs to be established with a terminal in a private network, which is not limited in the present invention.
参考图1,本发明实施例提供一种对等网络连接方法,包括:Referring to Fig. 1, an embodiment of the present invention provides a peer-to-peer network connection method, including:
S101,请求端获取P2P服务器提供的包含所述请求端所需资源的服务端的端口信息,所述端口信息包括服务端的私有端口映射的路由器的公网端口;S101, the requester obtains port information of the server provided by the P2P server and includes the resources required by the requester, and the port information includes the public network port of the router to which the private port of the server is mapped;
S102,所述请求端向所述路由器的公网端口发送对等网络连接请求,由所述路由器根据所述路由器的公网端口映射的所述服务端的私有端口将所述对等网络连接请求转发至所述服务端;S102, the requesting end sends a peer-to-peer network connection request to the public network port of the router, and the router forwards the peer-to-peer network connection request according to the private port of the server mapped to the public network port of the router to the server;
S103,所述请求端在接收到所述路由器转发的所述服务端响应所述对等网络连接请求的应答消息后,建立与所述服务端的对等网络连接。S103. The requesting end establishes a peer-to-peer network connection with the server after receiving a response message from the server forwarded by the router in response to the peer-to-peer network connection request.
其中,步骤S101中的P2P服务器中预先接收并存储了请求端上报的资源请求信息,资源请求信息包括所需资源的名称、内容、长度等,还存储有请求端和服务端上报的观影信息,例如请求端所观看的直播/点播节目的名称、总长度、当前播放帧等。当所述请求端为终端时,所述请求端还会将其端口信息上报至所述P2P服务器。另外,P2P服务器中还接收并存储了服务端上报的端口信息,端口信息中包括服务端的私有端口映射的路由器的公网端口,请求端将从所述P2P服务器中获取到服务端对应的路由器的公网端口,并在S102中将对等网络连接请求发送至路由器的公网端口。Wherein, the P2P server in step S101 receives and stores the resource request information reported by the requesting end in advance, and the resource request information includes the name, content, length, etc. of the required resource, and also stores the viewing information reported by the requesting end and the server end , such as the name, total length, current playing frame, etc. of the live/on-demand program watched by the requester. When the requesting end is a terminal, the requesting end will also report its port information to the P2P server. In addition, the P2P server also receives and stores the port information reported by the server. The port information includes the public network port of the router mapped to the private port of the server. public network port, and send the peer-to-peer network connection request to the public network port of the router in S102.
请求端和服务端将通过P2P服务器进行信息交换,即请求端获取到服务端的资源信息及端口信息,服务端也可获知请求端的资源请求信息、观影信息、端口信息等。请求端和服务端向P2P服务器上报资源请求信息可使用UTP、HTTP、Websocket协议中的任意一种。The requester and the server will exchange information through the P2P server, that is, the requester can obtain the resource information and port information of the server, and the server can also know the resource request information, viewing information, port information, etc. of the requester. The requester and the server can use any one of UTP, HTTP, and Websocket protocols to report resource request information to the P2P server.
步骤S102中,请求端将对等网络连接请求发送至服务端对应的路由器的公网端口,路由器在接收到请求端的对等网络连接请求后,会自动根据服务端的私有端口与路由器的公网端口的映射关系将对等网络连接请求转发至服务端。例如,当服务端位于公司的局域网内时,服务端的私有端口指的便是服务端的内网端口,而公网端口则指公司路由器的对外端口。In step S102, the requester sends the peer-to-peer network connection request to the public network port of the router corresponding to the server. After receiving the peer-to-peer network connection request from the requester, the router automatically connects the private port of the server with the public network port of the router. The mapping relationship forwards the peer-to-peer network connection request to the server. For example, when the server is located in the company's LAN, the private port of the server refers to the internal network port of the server, and the public network port refers to the external port of the company's router.
S103中,在服务端接收到请求端发送的对等网络连接请求时,会根据实际情况进行应答,如果服务端同意建立连接,则会向请求端反馈应答消息,服务端响应所述对等网络请求的应答消息的反馈路径是通过其对应的路由器的公网端口转发至请求端,请求端在收到所述应答消息后,成功建立起与所述服务端的对等网络连接。In S103, when the server receives the peer-to-peer network connection request sent by the requester, it will respond according to the actual situation. If the server agrees to establish a connection, it will feed back a response message to the requester, and the server will respond to the peer-to-peer network request. The feedback path of the response message of the request is forwarded to the requesting end through the public network port of the corresponding router, and the requesting end successfully establishes a peer-to-peer network connection with the server after receiving the response message.
本实施例中,针对服务端处于私网中的情况,提供了一种补充连接方式,将请求端的对等网络连接请求经路由器的公网端口转发至服务端的私有端口,从而建立请求端与服务端的对等网络连接。In this embodiment, for the situation that the server is in a private network, a supplementary connection method is provided, and the peer-to-peer network connection request of the requester is forwarded to the private port of the server through the public network port of the router, thereby establishing the connection between the requester and the server. peer-to-peer network connection.
本发明实施例提供的对等网络连接方法中,所述请求端和服务端可以是手机、电脑、云视频终端、电视等终端设备,而请求端还可以是HTML5网页端,例如用户通过HTML5网页端进行在线视频点播。由于HTML5网页端运行在浏览器中,其没有访问本地信息的权限,且当其处于私网中时,无法进行与路由器的端口映射,也就无法提供用于接收对等网络连接请求的端口信息,因此,请求端为HTML5网页端时,只能主动向处于P2P网络系统中的其它终端发起对等网络连接请求,而无法接受其它终端发出的对等网络连接请求。当然,本发明实施例提供的对等网络连接方法也适用于其它类型的请求端,以建立起P2P网络系统中处于私网中的各终端的对等网络连接。In the peer-to-peer network connection method provided by the embodiment of the present invention, the requesting end and the server end can be terminal devices such as mobile phones, computers, cloud video terminals, and televisions, and the requesting end can also be an HTML5 web page end. online video on demand. Since the HTML5 web page runs in a browser, it has no access to local information, and when it is in a private network, it cannot perform port mapping with the router, and cannot provide port information for receiving peer-to-peer network connection requests Therefore, when the requesting end is an HTML5 web page end, it can only actively initiate peer-to-peer network connection requests to other terminals in the P2P network system, but cannot accept peer-to-peer network connection requests sent by other terminals. Of course, the peer-to-peer network connection method provided by the embodiment of the present invention is also applicable to other types of requesters, so as to establish peer-to-peer network connections between terminals in the private network in the P2P network system.
参考图2,本发明实施例提供的对等网络连接方法中,S103之后,还包括:Referring to FIG. 2, in the peer-to-peer network connection method provided by the embodiment of the present invention, after S103, it also includes:
S104,所述请求端根据所述端口信息包括的服务端的私有端口映射的路由器的公网端口,接收所述路由器转发的所述服务端发送的资源。S104, the requesting end receives the resource sent by the server forwarded by the router according to the public network port of the router mapped to the private port of the server included in the port information.
在S103中成功建立起请求端和服务端的对等网络连接之后,请求端和服务端之间可进行资源的共享,请求端接收服务端发送的资源时,通过服务端对应的路由器的公网端口,接收所述路由器转发的所述服务端发送的资源。而且,当服务端的私有端口上开启Websocket协议时,请求端采用Websocket协议与服务端进行通信,在请求端和服务端成功建立起对等网络连接之后,请求端和服务端可进行双向通信,即请求端可接收服务端对应的路由器转发的所述服务端中的资源,请求端也可将其资源经服务端对应的路由器的公网端口转发至服务端。基于此,对于请求端为HTML5网页端的场景下,对等网络连接的建立具有主动和被动之分,而成功建立连接后,请求端和服务端将可实现双向通信,不再有主动和被动之分,这区别于现有的HTTP协议和其它单向通信协议,使P2P网络系统中各终端之间的资源共享更加灵活方便。After the peer-to-peer network connection between the requesting end and the server is successfully established in S103, resources can be shared between the requesting end and the server. , receiving the resource sent by the server and forwarded by the router. Moreover, when the Websocket protocol is enabled on the private port of the server, the requester uses the Websocket protocol to communicate with the server. After the requester and the server successfully establish a peer-to-peer network connection, the requester and the server can communicate bidirectionally, that is The requester can receive the resources in the server forwarded by the router corresponding to the server, and the requester can also forward its resources to the server through the public network port of the router corresponding to the server. Based on this, in the scenario where the requesting end is an HTML5 web page, the establishment of a peer-to-peer network connection can be divided into active and passive. After the connection is successfully established, the requesting end and the server will realize two-way communication, and there is no longer a distinction between active and passive. This is different from the existing HTTP protocol and other one-way communication protocols, making the resource sharing between terminals in the P2P network system more flexible and convenient.
当本发明实施例应用于请求端为播放器的场景中时,在执行对等网络连接之前,请求端可先从CDN的节点服务器中下载预定长度的缓冲资源;并在所述缓冲资源下载完成后,将所述缓冲资源之后的资源作为请求资源配置到所述资源请求信息中。When the embodiment of the present invention is applied to a scenario where the requesting end is a player, before performing a peer-to-peer network connection, the requesting end can first download a buffer resource of a predetermined length from the node server of the CDN; Afterwards, configure resources following the buffer resource as request resources in the resource request information.
请求端首先向CDN架构中的节点服务器请求一部分缓冲资源,例如请求端观看一部影片时可先供节点服务器中下载10S的缓冲数据,利用10S的缓冲时间,请求端可在缓冲时间内通过P2P方式继续寻找资源,即缓冲资源之后的资源。所述资源请求信息中可将请求端所需的资源进行分段,可根据从P2P服务器中获取的各服务端的资源信息向不同的服务端分别发起对等网络连接请求,分散式获取资源,以提高资源获取的速度。The requester first requests a part of the buffer resources from the node server in the CDN architecture. For example, when the requester watches a movie, it can first download 10S buffer data from the node server. Using the 10S buffer time, the requester can pass P2P within the buffer time. way to continue looking for the resource, that is, the resource after the buffered resource. In the resource request information, the resources required by the requesting end can be segmented, and peer-to-peer network connection requests can be initiated to different server ends according to the resource information of each server end obtained from the P2P server, and resources can be acquired in a distributed manner, so as to Improve the speed of resource acquisition.
参考图3,本发明实施例还提供一种对等网络连接方法,包括:Referring to FIG. 3, an embodiment of the present invention also provides a peer-to-peer network connection method, including:
S201,服务端根据其私有端口映射的路由器的公网端口生成端口信息;S201, the server generates port information according to the public network port of the router mapped to its private port;
S202,所述服务端将资源信息及端口信息上报至P2P服务器;S202, the server reports resource information and port information to the P2P server;
S203,所述服务端在接收到请求端发送的对等网络连接请求时,将响应所述对等网络连接请求的应答消息通过所述服务端的私有端口映射的所述路由器的公网端口转发至所述请求端,并建立与所述请求端的对等网络连接;S203, when the server receives the peer-to-peer network connection request sent by the requester, forward the response message in response to the peer-to-peer network connection request to the public network port of the router mapped to the private port of the server to The requesting end, and establishing a peer-to-peer network connection with the requesting end;
其中,所述对等网络连接请求由所述请求端在获取P2P服务器提供的包含所述请求端所需资源的服务端的端口信息后,根据所述端口信息包括的服务端的私有端口映射的路由器的公网端口,向所述路由器的公网端口发送,并由所述路由器根据所述路由器的公网端口映射的所述服务端的私有端口转发至所述服务端。Wherein, the peer-to-peer network connection request is obtained by the requesting end after obtaining the port information of the server end that contains the resources required by the requesting end provided by the P2P server, and according to the private port mapping of the server end included in the port information. The public network port is sent to the public network port of the router, and forwarded to the server by the private port of the server mapped by the router according to the public network port of the router.
S201中,当所述服务端处于私网中时,服务端将其私有端口映射的路由器的公网端口配置到端口信息中,例如,当服务端处于公司局域网中,服务端将其端口5000映射到路由器的端口8000,路由器的端口8000的地址等信息将配置到端口信息。步骤S202中,服务端的端口信息和资源信息将通过UTP、HTTP、Websocket协议中的任意一中上报至P2P服务器,请求端将从所述P2P服务器中获取到服务端的端口信息以及资源信息,并根据服务端的资源信息判断是否发送向其发送对等网络连接请求,如果服务端中缓存有请求端所需的资源,则请求端会根据服务端的端口信息获知服务端对应的路由器的公网端口,请求端的对等网络连接请求将发送至服务端对应的路由器的公网端口,路由器会自动将请求端的对等网络连接请求转发至服务端。In S201, when the server is in the private network, the server configures the public network port of the router mapped to its private port into the port information, for example, when the server is in the company's local area network, the server maps its port 5000 To the port 8000 of the router, the address of the port 8000 of the router and other information will be configured in the port information. In step S202, the port information and resource information of the server will be reported to the P2P server through any one of UTP, HTTP, and Websocket protocols, and the requester will obtain the port information and resource information of the server from the P2P server, and according to The server's resource information determines whether to send a peer-to-peer network connection request to it. If the server caches the resources required by the requester, the requester will learn the public network port of the router corresponding to the server based on the port information of the server. Request The peer-to-peer network connection request on the server side will be sent to the public network port of the router corresponding to the server side, and the router will automatically forward the peer-to-peer network connection request from the requesting side to the server side.
S203中,服务端接收到路由器转发的请求端的对等网络连接请求后,如果同意建立连接,则将应答消息通过路由器的公网端口转发至请求端,在请求端收到服务端的应答消息后,请求端和服务端可成功建立对等网络连接,并可开始双向传输资源。In S203, after the server receives the peer-to-peer network connection request from the requester forwarded by the router, if it agrees to establish a connection, the response message is forwarded to the requester through the public network port of the router, and after the requester receives the response message from the server, The requester and the server can successfully establish a peer-to-peer network connection, and can begin to transfer resources in both directions.
服务端的私有端口和路由器的公网端口的映射关系建立可采用多种方式,以下再以一实施例对S201进行举例说明。The mapping relationship between the private port of the server and the public network port of the router can be established in various ways, and S201 will be described below with an example.
S201包括:所述服务端根据所述路由器为所述服务端的私有端口分配的公网端口生成端口信息。S201 includes: the server generates port information according to the public network port allocated by the router to the private port of the server.
路由器可根据其各公网端口的闲置情况自动为处于私网中的各终端分配公网端口,并将公网端口与终端的私有端口的映射关系反馈至终端,本实施例中,服务端根据获知的其私有端口与路由器的公网端口的映射关系,将其私有端口映射的路由器的公网端口的信息生成端口信息。例如,可采用UPNP协议进行网络地址转换,将所述服务端的私有端口的网络地址映射到路由器的公网端口,并将所述路由器的公网端口的网络地址配置到所述端口信息中。The router can automatically allocate public network ports for each terminal in the private network according to the idle status of its public network ports, and feed back the mapping relationship between the public network port and the private port of the terminal to the terminal. In this embodiment, the server according to The mapping relationship between the private port and the public network port of the router is learned, and the information of the public network port of the router to which the private port is mapped is used to generate port information. For example, the UPNP protocol can be used for network address translation, the network address of the private port of the server is mapped to the public network port of the router, and the network address of the public network port of the router is configured in the port information.
本实施例中,还可由处于私网中的服务端通过UPNP协议请求路由器提供一公网端口以进行服务端私有端口的映射。请求端发送对等连接请求时,将根据所述服务端的端口信息中的路由器的公网端口的网络地址将所述对等网络连接请求发送至所述路由器的公网端口,公网端口则将所述对等网络连接请求转发至服务端,从而所述服务端接收到所述请求端的对等网络连接请求。In this embodiment, the server in the private network may also request the router to provide a public network port through the UPNP protocol for mapping the private port of the server. When the requesting end sends a peer-to-peer connection request, it will send the peer-to-peer network connection request to the public network port of the router according to the network address of the router's public network port in the port information of the server, and the public network port will The peer-to-peer network connection request is forwarded to the server, so that the server receives the peer-to-peer network connection request from the requester.
本发明实施例针对服务端处于私网中的场景,提供了一种服务端接收请求端的对等网络连接请求,并成功向请求端反馈应答消息以实现建立与请求端的对等网络连接的技术方案,为P2P网络系统中各终端处于不同网络场景中时提供了一种补充的网络连接方式,使得各终端可不受私网的限制,发挥服务端的功能,使得P2P网络系统中的资源共享更加方便,扩大了资源共享的适用范围。Aiming at the scenario where the server is in a private network, the embodiment of the present invention provides a technical solution in which the server receives the peer-to-peer network connection request from the requester and successfully feeds back a response message to the requester to establish a peer-to-peer network connection with the requester , provides a supplementary network connection method for each terminal in the P2P network system when it is in different network scenarios, so that each terminal can play the function of the server without being restricted by the private network, making resource sharing in the P2P network system more convenient. The scope of application of resource sharing has been expanded.
参考图4,本发明的实施例提供一种对等网络连接方法,包括:Referring to Fig. 4, an embodiment of the present invention provides a peer-to-peer network connection method, including:
S301,路由器接收请求端发送的对等网络连接请求,所述对等网络连接请求由所述请求端在获取P2P服务器提供的包含所述请求端所需资源的服务端的端口信息后,根据所述端口信息包括的服务端的私有端口映射的路由器的公网端口,向所述路由器的公网端口发送的;S301. The router receives the peer-to-peer network connection request sent by the requesting end. The peering network connection request is obtained by the requesting end according to the The public network port of the router mapped to the private port of the server included in the port information is sent to the public network port of the router;
S302,所述路由器根据所述路由器的公网端口映射的所述服务端的私有端口将所述对等网络连接请求转发至所述服务端;S302. The router forwards the peer-to-peer network connection request to the server according to the private port of the server mapped to the public network port of the router;
S303,所述路由器接收所述服务端发送的响应所述请求端发送的对等网络连接请求的应答消息,并将所述应答消息转发至所述请求端,以便于所述请求端在接收到所述路由器转发的所述服务端的应答消息后,建立与所述服务端的对等网络连接。S303. The router receives the response message sent by the server in response to the peer-to-peer network connection request sent by the requesting end, and forwards the response message to the requesting end, so that the requesting end receives After the router forwards the response message of the server, it establishes a peer-to-peer network connection with the server.
本实施例中,路由器接收请求端发送的对等网络连接请求,并将接收到的对等网络连接请求转发至服务端。由请求端先根据P2P服务器提供的包含请求端所需资源的服务端的端口信息获取到服务端对应的路由器的公网端口,之后再根据获取到的端口信息将对等网络连接请求发送至路由器的公网端口,路由器在接收到请求端发送的对等网络请求后,根据路由器的公网端口与服务端的私有端口的映射关系,将对等网络连接请求转发至服务端。In this embodiment, the router receives the peer-to-peer network connection request sent by the requesting end, and forwards the received peer-to-peer network connection request to the server end. The requester first obtains the public network port of the router corresponding to the server according to the port information of the server that contains the resources required by the requester provided by the P2P server, and then sends the peer-to-peer network connection request to the router according to the obtained port information. Public network port. After receiving the peer-to-peer network request sent by the requesting end, the router forwards the peer-to-peer network connection request to the server according to the mapping relationship between the public network port of the router and the private port of the server.
服务端在接收到对等网络连接请求后,会发出响应所述对等网络连接请求的应答消息,服务端发出的应答消息将发送至路由器的公网端口,路由器在会自动将服务器发送的应答消息转发至请求端,至此,在路由器的转发帮助下,请求端和服务端成功建立起对等网络连接,并可进行双向的资源共享,请求端与服务端进行资源共享过程中,路由器可依然承担转发的功能,以保证请求端和服务端的顺畅通信。After receiving the peer-to-peer network connection request, the server will send a response message in response to the peer-to-peer network connection request. The response message sent by the server will be sent to the public network port of the router, and the router will automatically send the response message sent by the server. The message is forwarded to the requesting end. So far, with the forwarding help of the router, the requesting end and the server successfully establish a peer-to-peer network connection, and can perform two-way resource sharing. During the resource sharing process between the requesting end and the server end, the router can still Undertake the function of forwarding to ensure smooth communication between the requester and the server.
以下以HTML5网页端作为请求端,处于私网中的电脑作为服务端为例进行本发明实施例的详细解释。Hereinafter, the embodiment of the present invention will be explained in detail by taking the HTML5 web page as the requesting end and the computer in the private network as the server as an example.
用户通过HTML5网页端中的播放器请求观看一部电影,在播放器中选择播放的影片后,播放器首先向CDN架构中的节点服务器请求下载10s的缓冲资源,下载完成后,播放器开始播放缓冲资源,播放器将在10S的缓冲时间内,通过对等网络连接的方式获取所述电影的资源,P2P网络系统中,网页端中的播放器(请求端)和各终端的播放器(服务端)均将观影信息上报至P2P服务器,观影信息中包含请求端或服务端的资源、端口、观看进度等等信息,观影信息为请求端和服务端提供了配对依据。例如,请求端获知服务端A、B和C中包含所述电影的资源,请求端分别向服务端A、B、C发起基于Webrte和Websocket协议的对等网络连接请求,服务端A、C处于公网中,请求端可与服务端A、C成功建立基于Webrtc协议的对等网络连接;服务端B处于私网中,请求端发起的基于Webrtc协议的连接请求失败,请求端通过解析P2P服务器提供的服务端B的端口信息,将基于Websocket协议的连接请求通过服务端B对应的路由器的公网端口转发至服务端B,服务端B在接收到请求端发送的对等网络连接请求后,将应答消息通过路由器的公网端口反馈给所述请求端,在获得服务端B反馈的应答消息后,请求端与服务端B成功建立了基于Websocket协议的对等网络连接。对于请求端来说,其采用两种协议分别向各服务端发起请求连接,在一种连接请求失败或中断的情况下,另一种连接请求可作为补充连接,从而提高了P2P方式进行资源获取的成功率,增大了P2P方式获取的资源量在网页端所需总资源量中所占的比例,进而减小了CDN架构的服务压力,基于Webrtc和Websocket协议的两种连接请求相互独立,相互补充,为P2P方式提供了更优化的连接方案。The user requests to watch a movie through the player on the HTML5 web page. After selecting the movie to play in the player, the player first requests the node server in the CDN architecture to download 10s of buffer resources. After the download is completed, the player starts to play Buffering resources, the player will obtain the resources of the movie through a peer-to-peer network connection within 10S buffering time. In the P2P network system, the player (requester) in the web page and the player (service) Both end) will report the viewing information to the P2P server. The viewing information includes information such as resources, ports, and viewing progress of the requesting end or server. The viewing information provides a pairing basis for the requesting end and the server. For example, the requester knows that the resources of the movie are contained in the servers A, B, and C, and the requester initiates peer-to-peer network connection requests based on the Webrte and Websocket protocols to the servers A, B, and C respectively, and the servers A, C are in In the public network, the requester can successfully establish a peer-to-peer network connection based on the Webrtc protocol with the servers A and C; the server B is in the private network, and the connection request based on the Webrtc protocol initiated by the requester fails, and the requester resolves the P2P server The provided port information of server B forwards the connection request based on the Websocket protocol to server B through the public network port of the router corresponding to server B. After server B receives the peer-to-peer network connection request sent by the requesting end, The response message is fed back to the requesting end through the public network port of the router, and after obtaining the response message fed back by the server B, the requesting end and the server B successfully establish a peer-to-peer network connection based on the Websocket protocol. For the requesting end, it uses two protocols to initiate a request connection to each server respectively. In the case of a connection request failure or interruption, the other connection request can be used as a supplementary connection, thus improving the P2P method for resource acquisition. The success rate increases the proportion of resources obtained by the P2P method in the total resources required by the web page, thereby reducing the service pressure of the CDN architecture. The two connection requests based on the Webrtc and Websocket protocols are independent of each other. They complement each other and provide a more optimized connection solution for the P2P method.
参考图5,本发明实施例提供一种对等网络连接装置,配置在P2P网络系统的请求端中,包括:Referring to FIG. 5, an embodiment of the present invention provides a peer-to-peer network connection device, which is configured in the requesting end of the P2P network system, including:
信息获取模块11,用于获取P2P服务器提供的包含所述请求端所需资源的服务端的端口信息,所述端口信息包括服务端的私有端口映射的路由器的公网端口;The information acquisition module 11 is used to acquire the port information of the service end provided by the P2P server that includes the resources required by the request end, and the port information includes the public network port of the router mapped to the private port of the service end;
连接请求模块12,用于向所述路由器的公网端口发送对等网络连接请求,由所述路由器根据所述路由器的公网端口映射的所述服务端的私有端口将所述对等网络连接请求转发至所述服务端;The connection request module 12 is configured to send a peer-to-peer network connection request to the public network port of the router, and the router sends the peer-to-peer network connection request to the private port of the server according to the public network port mapping of the router. Forward to the server;
连接建立模块13,用于在接收到所述路由器转发的所述服务端响应所述对等网络连接请求的应答消息后,建立与所述服务端的对等网络连接。The connection establishment module 13 is configured to establish a peer-to-peer network connection with the server after receiving a response message forwarded by the router in response to the peer-to-peer network connection request from the server.
其中,P2P服务器中预先接收并存储了本实施例中的对等网络连接装置上报的资源请求信息,资源请求信息包括所需资源的名称、内容、长度等,还存储有请求端和服务端上报的观影信息,例如请求端所观看的直播/点播节目的名称、总长度、当前播放帧等。当所述请求端为终端时,所述请求端还会将其端口信息上报至所述P2P服务器。另外,P2P服务器中还接收并存储了服务端上报的端口信息,端口信息中包括服务端的私有端口映射的路由器的公网端口,请求端将从所述P2P服务器中获取到服务端对应的路由器的公网端口,并在连接请求模块12中将对等网络连接请求发送至路由器的公网端口。Wherein, the resource request information reported by the peer-to-peer network connection device in this embodiment is pre-received and stored in the P2P server. The resource request information includes the name, content, length, etc. Viewing information, such as the name, total length, current playing frame, etc. of the live/on-demand program watched by the requesting end. When the requesting end is a terminal, the requesting end will also report its port information to the P2P server. In addition, the P2P server also receives and stores the port information reported by the server. The port information includes the public network port of the router mapped to the private port of the server. The public network port, and send the peer-to-peer network connection request to the public network port of the router in the connection request module 12.
请求端和服务端将通过P2P服务器进行信息交换,即请求端获取到服务端的资源信息及端口信息,服务端也可获知请求端的资源请求信息、观影信息、端口信息等。请求端和服务端向P2P服务器上报资源请求信息可使用UTP、HTTP、Websocket协议中的任意一种。The requester and the server will exchange information through the P2P server, that is, the requester can obtain the resource information and port information of the server, and the server can also know the resource request information, viewing information, port information, etc. of the requester. The requester and the server can use any one of UTP, HTTP, and Websocket protocols to report resource request information to the P2P server.
连接请求模块12中,请求端将对等网络连接请求发送至服务端对应的路由器的公网端口,路由器在接收到请求端的对等网络连接请求后,会自动根据服务端的私有端口与路由器的公网端口的映射关系将对等网络连接请求转发至服务端。例如,当服务端位于公司的局域网内时,服务端的私有端口指的便是服务端的内网端口,而公网端口则指公司路由器的对外端口。In the connection request module 12, the requester sends the peer-to-peer network connection request to the public network port of the router corresponding to the server. The peer-to-peer network connection request is forwarded to the server according to the mapping relationship of the network port. For example, when the server is located in the company's LAN, the private port of the server refers to the internal network port of the server, and the public network port refers to the external port of the company's router.
连接建立模块13中,在服务端接收到请求端发送的对等网络连接请求时,会根据实际情况进行应答,如果服务端同意建立连接,则会向请求端反馈应答消息,服务端响应所述对等网络请求的应答消息的反馈路径是通过其对应的路由器的公网端口转发至请求端,请求端在收到所述应答消息后,成功建立起与所述服务端的对等网络连接。In the connection establishment module 13, when the server receives the peer-to-peer network connection request sent by the requester, it will respond according to the actual situation. If the server agrees to establish a connection, it will feed back a response message to the requester, and the server will respond to the request. The feedback path of the reply message requested by the peer-to-peer network is forwarded to the requesting end through the public network port of the corresponding router, and the requesting end successfully establishes a peer-to-peer network connection with the server after receiving the reply message.
本实施例中,针对服务端处于私网中的情况,提供了一种补充连接方式,将请求端的对等网络连接请求经路由器的公网端口转发至服务端的私有端口,从而建立请求端与服务端的对等网络连接。In this embodiment, for the situation that the server is in a private network, a supplementary connection method is provided, and the peer-to-peer network connection request of the requester is forwarded to the private port of the server through the public network port of the router, thereby establishing the connection between the requester and the server. peer-to-peer network connection.
本发明实施例提供的对等网络连接装置适用于P2P网络系统的请求端,所述请求端和服务端可以是手机、电脑、云视频终端、电视等终端设备,而请求端还可以是HTML5网页端,例如用户通过HTML5网页端进行在线视频点播。由于HTML5网页端运行在浏览器中,其没有访问本地信息的权限,且当其处于私网中时,无法进行与路由器的端口映射,也就无法提供用于接收对等网络连接请求的端口信息,因此,请求端为HTML5网页端时,只能主动向处于P2P网络系统中的其它终端发起对等网络连接请求,而无法接受其它终端发出的对等网络连接请求。当然,本发明实施例提供的请求端也适用于其它类型的请求端,以建立起P2P网络系统中处于私网中的各终端的对等网络连接。The peer-to-peer network connection device provided by the embodiment of the present invention is suitable for the requesting end of the P2P network system. The requesting end and the server end can be mobile phones, computers, cloud video terminals, televisions and other terminal equipment, and the requesting end can also be an HTML5 web page For example, users can play online video on demand through the HTML5 web page. Since the HTML5 web page runs in a browser, it has no access to local information, and when it is in a private network, it cannot perform port mapping with the router, and cannot provide port information for receiving peer-to-peer network connection requests Therefore, when the requesting end is an HTML5 web page end, it can only actively initiate peer-to-peer network connection requests to other terminals in the P2P network system, but cannot accept peer-to-peer network connection requests sent by other terminals. Of course, the requester provided by the embodiment of the present invention is also applicable to other types of requesters, so as to establish a peer-to-peer network connection between terminals in a private network in a P2P network system.
参考图6,本发明实施例提供的对等网络连接装置,还包括:Referring to FIG. 6, the peer-to-peer network connection device provided by the embodiment of the present invention further includes:
数据传输模14,用于根据所述端口信息包括的服务端的私有端口映射的路由器的公网端口,接收所述路由器转发的所述服务端发送的资源。The data transmission module 14 is configured to receive the resource sent by the server forwarded by the router according to the public network port of the router mapped to the private port of the server included in the port information.
在所述连接建立模块13成功建立起请求端与服务端的对等网络连接之后,请求端和服务端之间可进行资源的共享,请求端接收服务端发送的资源时,通过服务端对应的路由器的公网端口,接收所述路由器转发的所述服务端发送的资源。而且,当服务端的私有端口上开启Websocket协议时,请求端采用Websocket协议与服务端进行通信,在请求端和服务端成功建立起对等网络连接之后,请求端和服务端可进行双向通信,即请求端可接收服务端对应的路由器转发的所述服务端中的资源,请求端也可将其资源经服务端对应的路由器的公网端口转发至服务端。基于此,对于请求端为HTML5网页端的场景下,对等网络连接的建立具有主动和被动之分,而成功建立连接后,请求端和服务端将可实现双向通信,不再有主动和被动之分,这区别于现有的HTTP协议和其它单向通信协议,使P2P网络系统中各终端之间的资源共享更加灵活方便。After the connection establishment module 13 successfully establishes the peer-to-peer network connection between the requester and the server, resource sharing can be performed between the requester and the server. The public network port of the router receives the resource sent by the server forwarded by the router. Moreover, when the Websocket protocol is enabled on the private port of the server, the requester uses the Websocket protocol to communicate with the server. After the requester and the server successfully establish a peer-to-peer network connection, the requester and the server can communicate bidirectionally, that is The requester can receive the resources in the server forwarded by the router corresponding to the server, and the requester can also forward its resources to the server through the public network port of the router corresponding to the server. Based on this, in the scenario where the requesting end is an HTML5 web page, the establishment of a peer-to-peer network connection can be divided into active and passive. After the connection is successfully established, the requesting end and the server will realize two-way communication, and there is no longer a distinction between active and passive. This is different from the existing HTTP protocol and other one-way communication protocols, making the resource sharing between terminals in the P2P network system more flexible and convenient.
当本发明实施例应用于请求端为播放器的场景中时,在执行对等网络连接之前,请求端可先从CDN的节点服务器中下载预定长度的缓冲资源;并在所述缓冲资源下载完成后,将所述缓冲资源之后的资源作为请求资源配置到所述资源请求信息中。When the embodiment of the present invention is applied to a scenario where the requesting end is a player, before performing a peer-to-peer network connection, the requesting end can first download a buffer resource of a predetermined length from the node server of the CDN; Afterwards, configure resources following the buffer resource as request resources in the resource request information.
请求端首先向CDN架构中的节点服务器请求一部分缓冲资源,例如请求端观看一部影片时可先供节点服务器中下载10S的缓冲数据,利用10S的缓冲时间,请求端可在缓冲时间内通过P2P方式继续寻找资源,即缓冲资源之后的资源。所述资源请求信息中可将请求端所需的资源进行分段,可根据从P2P服务器中获取的各服务端的资源信息向不同的服务端分别发起对等网络连接请求,分散式获取资源,以提高资源获取的速度。The requester first requests a part of the buffer resources from the node server in the CDN architecture. For example, when the requester watches a movie, it can first download 10S buffer data from the node server. Using the 10S buffer time, the requester can pass P2P within the buffer time. way to continue looking for the resource, that is, the resource after the buffered resource. In the resource request information, the resources required by the requesting end can be segmented, and peer-to-peer network connection requests can be initiated to different server ends according to the resource information of each server end obtained from the P2P server, and resources can be acquired in a distributed manner, so as to Improve the speed of resource acquisition.
参考图7,本发明实施例提供一种对等网络连接装置,配置在P2P网络系统的服务端中,包括:Referring to FIG. 7, an embodiment of the present invention provides a peer-to-peer network connection device, which is configured in the server of the P2P network system, including:
信息生成模块21,用于根据其私有端口映射的路由器的公网端口生成端口信息;Information generating module 21, for generating port information according to the public network port of the router of its private port mapping;
信息上报模块22,用于将资源信息及端口信息上报至P2P服务器;An information reporting module 22, configured to report resource information and port information to the P2P server;
响应模块23,用于在接收到请求端发送的对等网络连接请求时,将响应所述对等网络连接请求的应答消息通过所述服务端的私有端口映射的所述路由器的公网端口转发至所述请求端,并建立与所述请求端的对等网络连接;Response module 23, for when receiving the peer-to-peer network connection request sent by the requesting end, forward the response message in response to the peer-to-peer network connection request through the public network port of the router mapped by the private port of the server to The requesting end, and establishing a peer-to-peer network connection with the requesting end;
其中,所述对等网络连接请求由所述请求端在获取P2P服务器提供的包含所述请求端所需资源的服务端的端口信息后,根据所述端口信息包括的服务端的私有端口映射的路由器的公网端口,向所述路由器的公网端口发送,并由所述路由器根据所述路由器的公网端口映射的所述服务端的私有端口转发至所述服务端。Wherein, the peer-to-peer network connection request is obtained by the requesting end after obtaining the port information of the server end that contains the resources required by the requesting end provided by the P2P server, and according to the private port mapping of the server end included in the port information. The public network port is sent to the public network port of the router, and forwarded to the server by the private port of the server mapped by the router according to the public network port of the router.
本实施例提供的对等网络连接装置适用于P2P网络系统中的服务端,当所述服务端处于私网中时,服务端将其私有端口映射的路由器的公网端口配置到端口信息中,例如,当服务端处于公司局域网中,服务端将其端口5000映射到路由器的端口8000,路由器的端口8000的地址等信息将配置到端口信息。信息上报模块22中,服务端的端口信息和资源信息将通过UTP、HTTP、Websocket协议中的任意一中上报至P2P服务器,请求端将从所述P2P服务器中获取到服务端的端口信息以及资源信息,并根据服务端的资源信息判断是否发送向其发送对等网络连接请求,如果服务端中缓存有请求端所需的资源,则请求端会根据服务端的端口信息获知服务端对应的路由器的公网端口,请求端的对等网络连接请求将发送至服务端对应的路由器的公网端口,路由器会自动将请求端的对等网络连接请求转发至服务端。The peer-to-peer network connection device provided by this embodiment is applicable to the server in the P2P network system. When the server is in a private network, the server configures the public network port of the router mapped to its private port into the port information, For example, when the server is in the company's local area network, the server maps its port 5000 to the router's port 8000, and information such as the address of the router's port 8000 will be configured in the port information. In the information reporting module 22, the port information and resource information of the server will be reported to the P2P server through any one of UTP, HTTP, and Websocket protocols, and the requester will obtain the port information and resource information of the server from the P2P server, And judge whether to send a peer-to-peer network connection request based on the resource information of the server. If the resource required by the requester is cached in the server, the requester will know the public network port of the router corresponding to the server according to the port information of the server. , the peer-to-peer network connection request of the requesting end will be sent to the public network port of the router corresponding to the server, and the router will automatically forward the peer-to-peer network connection request of the requesting end to the server.
响应模块23接收到路由器转发的请求端的对等网络连接请求后,如果同意建立连接,则将应答消息通过路由器的公网端口转发至请求端,在请求端收到服务端的应答消息后,请求端和服务端可成功建立对等网络连接,并可开始双向传输资源。After the response module 23 receives the peer-to-peer network connection request of the requesting end forwarded by the router, if it agrees to establish a connection, the response message is forwarded to the requesting end through the public network port of the router. After the requesting end receives the response message of the server, the requesting end The peer-to-peer network connection can be successfully established with the server, and two-way resource transfer can begin.
所述信息生成模块21中私有端口和路由器的公网端口的映射关系建立可采用多种方式,以下再以一实施例对信息生成模块21进行详细说明。The mapping relationship between the private port in the information generation module 21 and the public network port of the router can be established in various ways, and the information generation module 21 will be described in detail in an embodiment below.
本实施例中,所述信息生成模块21,用于根据所述路由器为所述服务端的私有端口分配的公网端口生成端口信息。In this embodiment, the information generation module 21 is configured to generate port information according to the public network port allocated by the router to the private port of the server.
路由器可根据其各公网端口的闲置情况自动为处于私网中的各终端分配公网端口,并将公网端口与终端的私有端口的映射关系反馈至终端,本实施例中,信息生成模块21根据获知的其私有端口与路由器的公网端口的映射关系,将其私有端口映射的路由器的公网端口的信息生成端口信息。例如,可采用UPNP协议进行网络地址转换,将所述服务端的私有端口的网络地址映射到路由器的公网端口,并将所述路由器的公网端口的网络地址配置到所述端口信息中。The router can automatically allocate public network ports for each terminal in the private network according to the idle conditions of its public network ports, and feed back the mapping relationship between the public network port and the private port of the terminal to the terminal. In this embodiment, the information generation module 21. According to the known mapping relationship between the private port and the public network port of the router, generate port information from the information of the public network port of the router to which the private port is mapped. For example, the UPNP protocol can be used for network address translation, the network address of the private port of the server is mapped to the public network port of the router, and the network address of the public network port of the router is configured in the port information.
本实施例中,还可由处于私网中的服务端通过UPNP协议请求路由器提供一公网端口以进行服务端私有端口的映射。请求端发送对等连接请求时,将根据所述服务端的端口信息中的路由器的公网端口的网络地址将所述对等网络连接请求发送至所述路由器的公网端口,公网端口则将所述对等网络连接请求转发至服务端,从而所述服务端接收到所述请求端的对等网络连接请求。In this embodiment, the server in the private network may also request the router to provide a public network port through the UPNP protocol for mapping the private port of the server. When the requesting end sends a peer-to-peer connection request, it will send the peer-to-peer network connection request to the public network port of the router according to the network address of the router's public network port in the port information of the server, and the public network port will The peer-to-peer network connection request is forwarded to the server, so that the server receives the peer-to-peer network connection request from the requester.
本发明实施例针对服务端处于私网中的场景,提供了一种服务端接收请求端的对等网络连接请求,并成功向请求端反馈应答消息以实现建立与请求端的对等网络连接的技术方案,为P2P网络系统中各终端处于不同网络场景中时提供了一种补充的网络连接方式,使得各终端可不受私网的限制,发挥服务端的功能,使得P2P网络系统中的资源共享更加方便,扩大了资源共享的适用范围。Aiming at the scenario where the server is in a private network, the embodiment of the present invention provides a technical solution in which the server receives the peer-to-peer network connection request from the requester and successfully feeds back a response message to the requester to establish a peer-to-peer network connection with the requester , provides a supplementary network connection method for each terminal in the P2P network system when it is in different network scenarios, so that each terminal can play the function of the server without being restricted by the private network, making resource sharing in the P2P network system more convenient. The scope of application of resource sharing has been expanded.
参考图8,本发明实施例提供一种对等网络连接装置,配置在P2P网络系统的路由器中,包括:Referring to FIG. 8, an embodiment of the present invention provides a peer-to-peer network connection device configured in a router of a P2P network system, including:
请求接收模块31,用于接收请求端发送的对等网络连接请求,所述对等网络连接请求由所述请求端在获取P2P服务器提供的包含所述请求端所需资源的服务端的端口信息后,根据所述端口信息包括的服务端的私有端口映射的路由器的公网端口,向所述路由器的公网端口发送的;The request receiving module 31 is used to receive the peer-to-peer network connection request sent by the requesting end, and the peering network connection request is obtained by the requesting end after obtaining the port information of the server that contains the resources required by the requesting end provided by the P2P server , sending to the public network port of the router according to the public network port of the router mapped to the private port of the server included in the port information;
转发模块32,用于根据所述路由器的公网端口映射的所述服务端的私有端口将所述对等网络连接请求转发至所述服务端;A forwarding module 32, configured to forward the peer-to-peer network connection request to the server according to the private port of the server mapped to the public network port of the router;
所述转发模块32,还用于接收所述服务端发送的响应所述请求端发送的对等网络连接请求的应答消息,并将所述应答消息转发至所述请求端,以便于所述请求端在接收到所述路由器转发的所述服务端的应答消息后,建立与所述服务端的对等网络连接。The forwarding module 32 is also configured to receive a response message sent by the server in response to the peer-to-peer network connection request sent by the requesting end, and forward the response message to the requesting end, so that the request After receiving the response message of the server forwarded by the router, the terminal establishes a peer-to-peer network connection with the server.
本实施例发明实施例提供的对等网络连接装置适用于P2P网络系统中的路由器,路由器接收请求端发送的对等网络连接请求,并将接收到的对等网络连接请求转发至服务端。由请求端先根据P2P服务器提供的包含请求端所需资源的服务端的端口信息获取到服务端对应的路由器的公网端口,之后再根据获取到的端口信息将对等网络连接请求发送至路由器的公网端口,路由器在接收到请求端发送的对等网络请求后,根据路由器的公网端口与服务端的私有端口的映射关系,将对等网络连接请求转发至服务端。This embodiment The peer-to-peer network connection device provided by the embodiment of the invention is suitable for a router in a P2P network system. The router receives the peer-to-peer network connection request sent by the requesting end, and forwards the received peer-to-peer network connection request to the server end. The requester first obtains the public network port of the router corresponding to the server according to the port information of the server that contains the resources required by the requester provided by the P2P server, and then sends the peer-to-peer network connection request to the router according to the obtained port information. Public network port. After receiving the peer-to-peer network request sent by the requesting end, the router forwards the peer-to-peer network connection request to the server according to the mapping relationship between the public network port of the router and the private port of the server.
服务端在接收到对等网络连接请求后,会发出响应所述对等网络连接请求的应答消息,服务端发出的应答消息将发送至路由器的公网端口,路由器在会自动将服务器发送的应答消息转发至请求端,至此,在路由器的转发帮助下,请求端和服务端成功建立起对等网络连接,并可进行双向的资源共享,请求端与服务端进行资源共享过程中,路由器可依然承担转发的功能,以保证请求端和服务端的顺畅通信。After receiving the peer-to-peer network connection request, the server will send a response message in response to the peer-to-peer network connection request. The response message sent by the server will be sent to the public network port of the router, and the router will automatically send the response message sent by the server. The message is forwarded to the requesting end. So far, with the forwarding help of the router, the requesting end and the server successfully establish a peer-to-peer network connection, and can perform two-way resource sharing. During the resource sharing process between the requesting end and the server end, the router can still Undertake the function of forwarding to ensure smooth communication between the requester and the server.
本发明实施例还提供一种对等网络连接系统,包括请求端、服务端和路由器,其中所述请求端用于根据图1和2所示的对等网络连接方法向服务端发起对等网络连接,所述服务端用于根据图3所示的对等网络连接方法响应所述请求端的对等网络连接请求,所述路由器用于根据图4所示的对等网络连接方法转发所述请求端的对等网络请求及服务端的应答消息。The embodiment of the present invention also provides a peer-to-peer network connection system, including a requester, a server and a router, wherein the requester is used to initiate a peer-to-peer network to the server according to the peer-to-peer network connection method shown in Figures 1 and 2 connection, the server is used to respond to the request for a peer-to-peer network connection according to the peer-to-peer network connection method shown in Figure 3, and the router is used to forward the request according to the peer-to-peer network connection method shown in Figure 4 The peer-to-peer network request of the client and the response message of the server.
以上所描述的装置实施例仅仅是示意性的,其中所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。本领域普通技术人员在不付出创造性的劳动的情况下,即可以理解并实施。The device embodiments described above are only illustrative, and the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in One place, or it can be distributed to multiple network elements. Part or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. It can be understood and implemented by those skilled in the art without any creative effort.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到各实施方式可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件。基于这样的理解,上述技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品可以存储在计算机可读存储介质中,如ROM/RAM、磁碟、光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行各个实施例或者实施例的某些部分所述的方法。Through the above description of the implementations, those skilled in the art can clearly understand that each implementation can be implemented by means of software plus a necessary general hardware platform, and of course also by hardware. Based on this understanding, the essence of the above technical solution or the part that contributes to the prior art can be embodied in the form of software products, and the computer software products can be stored in computer-readable storage media, such as ROM/RAM, magnetic discs, optical discs, etc., including several instructions to make a computer device (which may be a personal computer, server, or network device, etc.) execute the methods described in various embodiments or some parts of the embodiments.
最后应说明的是:以上实施例仅用以说明本发明的技术方案,而非对其限制;尽管参照前述实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明各实施例技术方案的精神和范围。Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: it can still be Modifications are made to the technical solutions described in the foregoing embodiments, or equivalent replacements are made to some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the various embodiments of the present invention.
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201511020640.XACN105897853A (en) | 2015-12-29 | 2015-12-29 | Peer-to-peer network connection method and device |
| PCT/CN2016/096010WO2017113816A1 (en) | 2015-12-29 | 2016-08-19 | Method and device for peer-to-peer network connection |
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201511020640.XACN105897853A (en) | 2015-12-29 | 2015-12-29 | Peer-to-peer network connection method and device |
| Publication Number | Publication Date |
|---|---|
| CN105897853Atrue CN105897853A (en) | 2016-08-24 |
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201511020640.XAPendingCN105897853A (en) | 2015-12-29 | 2015-12-29 | Peer-to-peer network connection method and device |
| Country | Link |
|---|---|
| CN (1) | CN105897853A (en) |
| WO (1) | WO2017113816A1 (en) |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN106791968A (en)* | 2016-11-15 | 2017-05-31 | 武汉斗鱼网络科技有限公司 | A kind of data download method and device |
| CN109819336A (en)* | 2019-01-31 | 2019-05-28 | 湖南快乐阳光互动娱乐传媒有限公司 | Method and system for downloading fragments based on size of play cache |
| CN109936602A (en)* | 2017-12-18 | 2019-06-25 | 厦门本能管家科技有限公司 | It is a kind of based on the P2P network system pushed in real time |
| CN113364865A (en)* | 2021-06-03 | 2021-09-07 | 湖南快乐阳光互动娱乐传媒有限公司 | Resource acquisition method, device, readable medium and equipment |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN112019625B (en)* | 2020-08-31 | 2023-01-31 | 重庆紫光华山智安科技有限公司 | Websocket-based message pushing method, system, device and medium |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101252605A (en)* | 2008-04-03 | 2008-08-27 | 杭州华三通信技术有限公司 | Multimedia communication method, system and apparatus traversing network address conversion equipment |
| CN101355568A (en)* | 2008-09-03 | 2009-01-28 | 中兴通讯股份有限公司 | Method and system for binding router interface supported by static state PAT |
| CN101369959A (en)* | 2007-08-14 | 2009-02-18 | 中兴通讯股份有限公司 | Network address conversion traversing method supporting point-to-point service |
| US20110317554A1 (en)* | 2010-06-28 | 2011-12-29 | Microsoft Corporation | Distributed and Scalable Network Address Translation |
| CN104426726A (en)* | 2013-09-11 | 2015-03-18 | 郑州朗鑫智能电子科技有限公司 | Intelligent home system for protecting privacy and information safety of user |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101699801B (en)* | 2009-10-30 | 2011-09-28 | 孙喜明 | Data transmission method and virtual peer-to-peer network for data transmission |
| CN102055816A (en)* | 2010-12-28 | 2011-05-11 | 华为技术有限公司 | Communication method, business server, intermediate equipment, terminal and communication system |
| WO2012103938A1 (en)* | 2011-02-01 | 2012-08-09 | Telefonaktiebolaget L M Ericsson (Publ) | Routing traffic towards a mobile node |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101369959A (en)* | 2007-08-14 | 2009-02-18 | 中兴通讯股份有限公司 | Network address conversion traversing method supporting point-to-point service |
| CN101252605A (en)* | 2008-04-03 | 2008-08-27 | 杭州华三通信技术有限公司 | Multimedia communication method, system and apparatus traversing network address conversion equipment |
| CN101355568A (en)* | 2008-09-03 | 2009-01-28 | 中兴通讯股份有限公司 | Method and system for binding router interface supported by static state PAT |
| US20110317554A1 (en)* | 2010-06-28 | 2011-12-29 | Microsoft Corporation | Distributed and Scalable Network Address Translation |
| CN104426726A (en)* | 2013-09-11 | 2015-03-18 | 郑州朗鑫智能电子科技有限公司 | Intelligent home system for protecting privacy and information safety of user |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN106791968A (en)* | 2016-11-15 | 2017-05-31 | 武汉斗鱼网络科技有限公司 | A kind of data download method and device |
| CN106791968B (en)* | 2016-11-15 | 2019-11-05 | 武汉斗鱼网络科技有限公司 | A kind of data download method and device |
| CN109936602A (en)* | 2017-12-18 | 2019-06-25 | 厦门本能管家科技有限公司 | It is a kind of based on the P2P network system pushed in real time |
| CN109936602B (en)* | 2017-12-18 | 2022-03-11 | 本无链科技(深圳)有限公司 | P2P network system based on real-time push |
| CN109819336A (en)* | 2019-01-31 | 2019-05-28 | 湖南快乐阳光互动娱乐传媒有限公司 | Method and system for downloading fragments based on size of play cache |
| CN109819336B (en)* | 2019-01-31 | 2020-12-04 | 湖南快乐阳光互动娱乐传媒有限公司 | Method and system for downloading fragments based on size of play cache |
| CN113364865A (en)* | 2021-06-03 | 2021-09-07 | 湖南快乐阳光互动娱乐传媒有限公司 | Resource acquisition method, device, readable medium and equipment |
| Publication number | Publication date |
|---|---|
| WO2017113816A1 (en) | 2017-07-06 |
| Publication | Publication Date | Title |
|---|---|---|
| KR102514250B1 (en) | Method, Apparatus and System for Selecting a Mobile Edge Computing Node | |
| CN103067292B (en) | The load-balancing method of a kind of sing on web Socket transmission and device | |
| US20160373342A1 (en) | Method and apparatus for multipath media delivery | |
| WO2014183582A1 (en) | Distributed iptv multi-screen gateway and iptv multi-screen interaction method | |
| CN105897853A (en) | Peer-to-peer network connection method and device | |
| WO2015124045A1 (en) | Channel establishing method and apparatus | |
| CN104901860B (en) | The system and method that a kind of NDN and CDN interconnects | |
| CN101997822A (en) | Streaming media content delivery method, system and equipment | |
| US11671487B1 (en) | Port prediction for peer-to-peer communications | |
| JP2019536355A (en) | Data streaming support control based on node type | |
| CN101567769A (en) | Data retransmission method, system and peer-to-peer node | |
| CN108418789A (en) | A communication system based on WebRTC, its communication method, and a signaling server | |
| CN102413052B (en) | A kind of method of access network, Apparatus and system | |
| CN101662508B (en) | Method for data transmission based on point-to-point protocol, device and system thereof | |
| CN115865878A (en) | Transmission control method and device of media stream, storage medium and electronic equipment | |
| CN115379010A (en) | A container network construction method, device, equipment and storage medium | |
| CN103560937A (en) | Data accessing method and entry server | |
| CN111669333A (en) | Data transmission method, apparatus, computing device and storage medium | |
| WO2016095510A1 (en) | Path selection method, device and system | |
| CN102067516A (en) | Method and device for requesting multicast, processing multicast request and assisting it | |
| CN107483628B (en) | One-way proxy method and system based on DPDK | |
| CN105681266A (en) | Communication cluster method and device for MMTel (MultiMedia Telephony) | |
| CN101471954A (en) | Method for implementing network service, network service entity and intelligent network system | |
| CN113542395B (en) | Message processing method and message processing system | |
| WO2009086763A1 (en) | Method, system and device for switching source |
| Date | Code | Title | Description |
|---|---|---|---|
| C06 | Publication | ||
| PB01 | Publication | ||
| C10 | Entry into substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| WD01 | Invention patent application deemed withdrawn after publication | Application publication date:20160824 | |
| WD01 | Invention patent application deemed withdrawn after publication |