CN106331195B - Data receiving and sending method and device - Google Patents

Data receiving and sending method and device Download PDF

Info

Publication number
CN106331195B
CN106331195B CN201510351869.5A CN201510351869A CN106331195B CN 106331195 B CN106331195 B CN 106331195B CN 201510351869 A CN201510351869 A CN 201510351869A CN 106331195 B CN106331195 B CN 106331195B
Authority
CN
China
Prior art keywords
server
client
information
port
sending
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201510351869.5A
Other languages
Chinese (zh)
Other versions
CN106331195A (en
Inventor
柏林玲
张新星
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
ZTE Corp
Original Assignee
ZTE Corp
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by ZTE Corp filed Critical ZTE Corp
Priority to CN201510351869.5A priority Critical patent/CN106331195B/en
Priority to PCT/CN2016/085880 priority patent/WO2016206554A1/en
Publication of CN106331195A publication Critical patent/CN106331195A/en
Application granted granted Critical
Publication of CN106331195B publication Critical patent/CN106331195B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/25Mapping addresses of the same type
    • H04L61/2503Translation of Internet protocol [IP] addresses
    • H04L61/256NAT traversal
    • H04L61/2575NAT traversal using address mapping retrieval, e.g. simple traversal of user datagram protocol through session traversal utilities for NAT [STUN]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/25Mapping addresses of the same type
    • H04L61/2503Translation of Internet protocol [IP] addresses
    • H04L61/2521Translation architectures other than single NAT servers

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)
  • Small-Scale Networks (AREA)

Abstract

The invention provides a method and a device for receiving and sending data, wherein the method for receiving the data comprises the following steps: the method comprises the steps that a client side obtains information of a receiving port of the client side and information of a sending port of a server side, wherein the receiving port is used for the client side to receive data, the sending port is used for the server side to send data, and the client side is accessed to a network through a first NAT; the client sends a penetration message to the server through the first NAT according to the information of the sending port, wherein the penetration message is used for the first NAT to record the mapping relation between the information of the sending port and the information of the receiving port, and the mapping relation is used for allowing the data sent by the server to reach the client through penetrating the first NAT; and the client receives data which is sent by the server and reaches the client by penetrating through the first NAT. The problem that direct access of the client and the server is obstructed when the client and the server are located behind different NAT equipment in the related technology is solved.

Description

Data receiving and sending method and device
Technical Field
The present invention relates to the field of communications, and in particular, to a data receiving and transmitting method and apparatus.
Background
With the gradual exhaustion of IPv4 Address resources, Network Address Translation (NAT) technology is widely used, and the original data transmission flow between the client and the server may not be suitable for a Network system networked through the NAT. Taking Real Time Streaming Protocol (RTSP) as an example, RTSP is an application layer Protocol in TCP/IP Protocol system, and defines how to effectively transmit multimedia data through IP network by an application program. Fig. 1 is an interaction flowchart of an RTSP protocol in the related art, and as shown in fig. 1, an RTSP client and an RTSP server may directly interact with each other, which is very convenient.
However, as NAT is added to the related networking system, the RTSP client and the RTSP server are located behind different NAT devices and access to the Internet (Internet) through the respective NAT devices, and in such a scenario, direct access between the RTSP client and the RTSP server is hindered.
Aiming at the problem that direct access between a client and a server is obstructed when the client and the server are positioned behind different NAT equipment in the related technology, an effective solution is not provided at present.
Disclosure of Invention
The invention mainly aims to provide a data receiving and sending method and a data receiving and sending device, so as to at least solve the problem that direct access between a client and a server is obstructed when the client and the server are positioned behind different NAT equipment in the related art.
In order to achieve the above object, according to an aspect of the present invention, there is provided a data receiving method including: the method comprises the steps that a client side obtains information of a receiving port of the client side and information of a sending port of a server side, wherein the receiving port is used for the client side to receive data, the sending port is used for the server side to send data, and the client side is accessed to a network through a first network address translator NAT; the client sends a penetration message to the server through the first NAT according to the information of the sending port, wherein the penetration message is used for the first NAT to record the mapping relationship between the information of the sending port and the information of the receiving port, and the mapping relationship is used for allowing the data sent by the server to reach the client through penetrating through the first NAT; and the client receives data which is sent by the server and reaches the client by penetrating through the first NAT.
Optionally, the obtaining, by the client, information of the receiving port of the client and information of the sending port of the server includes: the client creates the receiving port; the client acquires the information of the receiving port; the client sends a request message for requesting to acquire the information of the sending port to the server through a relay server, wherein the request message carries the information of the receiving port, and the information of the receiving port is used for the server to directly send data to the receiving port; and the client receives a response message returned by the server through the relay server according to the request message, wherein the response message carries the information of the sending port.
Optionally, after the client receives data that is sent by the server and reaches the client by penetrating through the first NAT, the method further includes: the client sends a termination request to the server through the relay server, wherein the termination request is used for requesting the server to stop sending data to the client.
Optionally, the method comprises at least one of: the client comprises a real-time streaming protocol (RTSP) client and/or the server comprises an RTSP server; the information of the sending port comprises a public network Internet Protocol (IP) address of the sending port and a NAT mapping public network port number; the information of the receiving port comprises a public network Internet Protocol (IP) address of the receiving port and a NAT mapping public network port number.
According to another aspect of the present invention, there is provided another data transmission method, including: the method comprises the steps that a server side sends information of a sending port, used for sending data, of the server side to a client side, wherein the client side is accessed to a network through a first Network Address Translator (NAT), the information of the sending port is used for the client side to send a penetration message to the server side through the first NAT, the penetration message is used for the first NAT to record the mapping relation between the information of the sending port and the information of a receiving port, used for receiving data, of the client side, and the mapping relation is used for allowing the data sent by the server side to penetrate through the first NAT and reach the client side; and the server side sends data to the client side, wherein the data reaches the client side through the first NAT.
Optionally, the sending, by the server, information of a sending port of the server, which is used for sending data, to the client includes: the server side acquires a request message which is sent by the client side and used for requesting to acquire the information of the sending port through a relay server, wherein the request message carries the information of the receiving port; the server side creates the sending port according to the request message; the server side acquires the information of the sending port; and the server sends a response message to the client through the relay server, wherein the response message carries the information of the sending port.
Optionally, the accessing, by the server, to the network through the second NAT, the sending, by the server, to the client through the relay server, information of a sending port of the server, where the sending port is used to send data, includes: the server sends the information of the sending port to the relay server through the second NAT, wherein the information of the sending port is sent to the client by the relay server, the information of the sending port is used for the second NAT to record the mapping relation between the information of the sending port and the information of the receiving port, and the mapping relation is used for allowing the data sent by the client to reach the server by penetrating through the second NAT.
Optionally, after the server sends data to the client, the method further includes: the server receives a termination request sent by the client through a relay server; and the server stops sending data to the client according to the termination request.
Optionally, the method comprises at least one of: the client comprises a real-time streaming protocol (RTSP) client and/or the server comprises an RTSP server; the information of the sending port comprises a public network Internet Protocol (IP) address of the sending port and a NAT mapping public network port number; the information of the receiving port comprises a public network Internet Protocol (IP) address of the receiving port and a NAT mapping public network port number.
According to still another aspect of the present invention, there is provided a data receiving apparatus, applied to a client, including: the system comprises an acquisition module, a first Network Address Translator (NAT), a second NAT and a third NAT, wherein the acquisition module is used for acquiring information of a receiving port of a client and information of a sending port of a server, the receiving port is used for the client to receive data, the sending port is used for the server to send data, and the client is accessed to a network through the first NAT; a first sending module, configured to send a penetration packet to the server through the first NAT according to the information of the sending port, where the penetration packet is used for the first NAT to record a mapping relationship between the information of the sending port and the information of the receiving port, and the mapping relationship is used to allow data sent by the server to reach the client through penetrating through the first NAT; and the first receiving module is used for receiving the data which is sent by the server and reaches the client by penetrating through the first NAT.
Optionally, the obtaining module includes: a first creating unit configured to create the receiving port; a first obtaining unit, configured to obtain information of the receiving port; a first sending unit, configured to send, to the server through a relay server, a request message for requesting to obtain information of the sending port, where the request message carries information of the receiving port, and the information of the receiving port is used for the server to directly send data to the receiving port; and the receiving unit is used for receiving a response message returned by the server through the relay server according to the request message, wherein the response message carries the information of the sending port.
Optionally, the apparatus further comprises: and a second sending module, configured to send a termination request to the server through a relay server, where the termination request is used to request the server to stop sending data to the client.
Optionally, the apparatus comprises at least one of: the client comprises a real-time streaming protocol (RTSP) client and/or the server comprises an RTSP server; the information of the sending port comprises a public network Internet Protocol (IP) address of the sending port and a NAT mapping public network port number; the information of the receiving port comprises a public network Internet Protocol (IP) address of the receiving port and a NAT mapping public network port number.
According to another aspect of the present invention, there is provided a data transmission apparatus, applied in a server, including: a third sending module, configured to send information of a sending port, used for sending data, of the server to a client, where the client accesses a network through a first network address translator NAT, the information of the sending port is used for the client to send a penetration packet to the server through the first NAT, the penetration packet is used for the first NAT to record a mapping relationship between the information of the sending port and information of a receiving port, used for receiving data, of the client, and the mapping relationship is used for allowing data sent by the server to reach the client through the first NAT; and the fourth sending module is used for sending data to the client, wherein the data reaches the client through the first NAT.
Optionally, the third sending module includes: a second obtaining unit, configured to obtain, by a relay server, a request message sent by the client for requesting to obtain information of the sending port, where the request message carries information of the receiving port; a second creating unit configured to create the sending port according to the request message; a third obtaining unit, configured to obtain information of the sending port; and a second sending unit, configured to send a response message to the client through the relay server, where the response message carries information of the sending port.
Optionally, the server accesses the network through a second NAT, and the third sending module includes: and sending the information of the sending port to a relay server through the second NAT, wherein the information of the sending port is sent to the client by the relay server, the information of the sending port is used for the second NAT to record the mapping relation between the information of the sending port and the information of the receiving port, and the mapping relation is used for allowing the data sent by the client to reach the server by penetrating through the second NAT.
Optionally, the apparatus further comprises: a second receiving module, configured to receive a termination request sent by the client through a relay server; and the termination module is used for stopping sending data to the client according to the termination request.
Optionally, the apparatus comprises at least one of: the client comprises a real-time streaming protocol (RTSP) client and/or the server comprises an RTSP server; the information of the sending port comprises a public network Internet Protocol (IP) address of the sending port and a NAT mapping public network port number; the information of the receiving port comprises a public network Internet Protocol (IP) address of the receiving port and a NAT mapping public network port number.
According to the invention, a client is adopted to obtain the information of a receiving port of the client and the information of a sending port of a server, wherein the receiving port is used for the client to receive data, the sending port is used for the server to send data, and the client is accessed to a network through a first network address translator NAT; the client sends a penetration message to the server through the first NAT according to the information of the sending port, wherein the penetration message is used for the first NAT to record the mapping relationship between the information of the sending port and the information of the receiving port, and the mapping relationship is used for allowing the data sent by the server to reach the client through penetrating through the first NAT; the client receives the data which is sent by the server and reaches the client by penetrating through the first NAT, so that the client and the server can directly receive and send the data, the problem that direct access between the client and the server is obstructed when the client and the server are positioned behind different NAT equipment in the related technology is solved, the direct access between the client and the server can be realized, and the efficiency of data interaction between the client and the server is improved.
Drawings
The accompanying drawings, which are included to provide a further understanding of the invention and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the invention and together with the description serve to explain the invention without limiting the invention. In the drawings:
fig. 1 is an interaction flowchart of an RTSP protocol in the related art;
fig. 2 is a flowchart of a data receiving method according to an embodiment of the present invention;
fig. 3 is a flowchart of a data transmission method according to an embodiment of the present invention;
fig. 4 is a block diagram of a structure of a data receiving apparatus according to an embodiment of the present invention;
fig. 5 is a block diagram of the acquisition module 42 in the data receiving apparatus according to the embodiment of the present invention;
fig. 6 is a block diagram of a preferred configuration of a data receiving apparatus according to an embodiment of the present invention;
fig. 7 is a block diagram of a structure of a data transmission apparatus according to an embodiment of the present invention;
fig. 8 is a block diagram of a third transmission module 72 in the data transmission apparatus according to the embodiment of the present invention;
fig. 9 is a block diagram of a preferred configuration of a data transmission apparatus according to an embodiment of the present invention;
FIG. 10 is a block diagram of a system architecture according to an embodiment of the present invention;
fig. 11 is an interaction flowchart of an RTSP client and a server according to an embodiment of the present invention.
Detailed Description
It should be noted that the embodiments and features of the embodiments in the present application may be combined with each other without conflict. The present invention will be described in detail below with reference to the embodiments with reference to the attached drawings.
The steps illustrated in the flow charts of the drawings may be performed in a computer system such as a set of computer-executable instructions and, although a logical order is illustrated in the flow charts, in some cases, the steps illustrated or described may be performed in an order different than here.
In the following embodiments, "first" and "second" are used for distinction only and do not limit the order.
An embodiment of the present invention provides a data receiving method, and fig. 2 is a flowchart of the data receiving method according to the embodiment of the present invention, and as shown in fig. 2, the method includes:
step S202: the method comprises the steps that a client side obtains information of a receiving port of the client side and information of a sending port of a server side, wherein the receiving port is used for the client side to receive data, the sending port is used for the server side to send data, and the client side is accessed to a network through a first NAT;
step S204: the client sends a penetration message to the server through the first NAT according to the information of the sending port, wherein the penetration message is used for the first NAT to record the mapping relation between the information of the sending port and the information of the receiving port, and the mapping relation is used for allowing the data sent by the server to reach the client through penetrating the first NAT;
step S206: and the client receives data which is sent by the server and reaches the client by penetrating through the first NAT.
Through the processing steps, the client and the server can directly receive and send data, the problem that direct access between the client and the server is obstructed when the client and the server are located behind different NAT equipment in the related technology is solved, the direct access between the client and the server can be realized, and the efficiency of data interaction between the client and the server is improved.
In an alternative embodiment, step S202 may be implemented by: a client establishes a receiving port for receiving data; the client acquires the information of the receiving port; the client sends a request message for requesting to acquire the information of the sending port to the server through the relay server, wherein the request message carries the information of the receiving port, and the information of the receiving port is used for the server to directly send data to the receiving port; and the client receives a response message returned by the server through the relay server according to the request message, wherein the response message carries the information of the sending port. In this embodiment, the client sends the information of the receiving port for receiving the data to the server through the relay server, so that the server can determine the interface of the client for receiving the data sent by the server, and further determine the destination address when the server sends the data, and simultaneously request the server for the information of the sending port for sending the data, so as to send the penetration packet to the server.
In an optional embodiment, after step S206, the method further includes: and the client sends a termination request to the server through the relay server, wherein the termination request is used for requesting the server to stop sending data to the client. In this optional embodiment, after the client does not need to receive the data transmitted by the server, the client may notify the server in a manner of sending a request, so that the server disconnects the direct communication of the client, thereby saving system resources.
In the above described embodiment, the client may include a real-time streaming protocol RTSP client and/or the server may include an RTSP server; the information of the sending port can comprise a public network Internet Protocol (IP) address of the sending port and a NAT mapping public network port number; the information of the receiving port may include a public network internet protocol IP address of the receiving port and a NAT mapped public network port number. Of course, the client and the server may also be other clients and servers besides the RTSP protocol, which is not illustrated here.
The foregoing embodiments and implementations are described from the perspective of a client, and the following describes the present invention from the perspective of a server, in an embodiment of the present invention, a data transmission method is further provided, and fig. 3 is a flowchart of the data transmission method according to the embodiments of the present invention, as shown in fig. 3, the method includes:
step S302: the method comprises the steps that a server side sends information of a sending port, used for sending data, of the server side to a client side, wherein the client side is accessed into a network through a first NAT, the information of the sending port is used for the client side to send a penetration message to the server side through the first NAT, the penetration message is used for the first NAT to record the mapping relation between the information of the sending port and the information of a receiving port, used for receiving data, of the client side, and the mapping relation is used for allowing the data sent by the server side to penetrate through the first NAT and reach the client side;
step S304: and the server side sends data to the client side, wherein the data reaches the client side through the first NAT.
Through the processing steps, the client and the server can directly receive and send data, and the problem that direct access between the client and the server is obstructed when the client and the server are positioned behind different NAT equipment in the related technology is solved, so that the direct access between the client and the server is realized, and the efficiency of data interaction between the client and the server is improved.
In an alternative embodiment, step S302 may be implemented by taking the following steps: a server side acquires a request message which is sent by a client side and used for requesting to acquire information of a sending port through a relay server, wherein the request message carries information of a receiving port; the server side creates a sending port according to the request message; the server side obtains the information of the sending port; and the server sends a response message to the client through the relay server, wherein the response message carries the information of the sending port. In this optional embodiment, before sending the information of the sending port to the client, the server first receives the request message of the client, and obtains the information of the receiving port of the client from the request message, thereby facilitating the direct data transparent transmission with the client.
In an alternative embodiment, step S304 may be implemented according to the following steps: the server accesses the network through the second NAT, and sends information of the sending port to the relay server through the second NAT, wherein the information of the sending port is sent to the client by the relay server, the information of the sending port is used for the second NAT to record a mapping relation between the information of the sending port and the information of the receiving port, and the mapping relation is used for allowing data sent by the client to reach the server by penetrating through the second NAT. In this embodiment, the second NAT on the server side records the mapping relationship between the information on the client receiving port and the information on the server sending port, so that the data of the client is conveniently transmitted through the second NAT and directly sent to the server.
In another optional embodiment, after step S304, the method may further include: a server receives a termination request sent by a client through a relay server; and the server stops sending data to the client according to the termination request. In the optional embodiment, after the access is completed, the server disconnects the direct communication with the client according to the termination request, so that the system resources are saved.
In the above embodiments, the client may include a real-time streaming protocol RTSP client and/or the server may include an RTSP server; the information of the sending port comprises a public network Internet Protocol (IP) address of the sending port and a NAT mapping public network port number; the information of the receiving port comprises a public network Internet Protocol (IP) address of the receiving port and a NAT mapping public network port number. Of course, the above-mentioned clients and servers may also be other clients and servers besides the RTSP protocol, which is not illustrated herein.
Through the above description of the embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but the former is a better implementation mode in many cases. Based on such understanding, the technical solution of the present invention or a part of the contribution to the prior art can be essentially embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a middle-end device (such as a mobile phone, a computer, a server, or a network device) to execute the method according to the embodiments of the present invention.
The present embodiment further provides a data receiving and sending apparatus, where the apparatus is configured to implement the above data receiving and sending method embodiment and optional embodiments, and details of which have been already described are not described herein again. As used below, the term "module" may be a combination of software and/or hardware that implements a predetermined function. Although the means described in the embodiments below are preferably implemented in software, an implementation in hardware or a combination of software and hardware is also possible and contemplated.
Fig. 4 is a block diagram of a data receiving apparatus according to an embodiment of the present invention, which may be applied to a client, as shown in fig. 4, the apparatus including: an obtaining module 42, a first sending module 44 and a first receiving module 46, which are explained below.
The acquiring module 42 is configured to acquire information of a receiving port of a client and information of a sending port of a server, where the receiving port is used for the client to receive data, the sending port is used for the server to send data, and the client accesses a network through a first NAT; a first sending module 44, connected to the obtaining module 42, configured to send a penetration packet to the server through the first NAT according to the information of the sending port, where the penetration packet is used for the first NAT to record a mapping relationship between the information of the sending port and the information of the receiving port, and the mapping relationship is used to allow data sent by the server to reach the client through penetrating the first NAT; and the first receiving module 46 is connected to the first sending module 44, and is configured to receive data that is sent by the server and reaches the client by penetrating through the first NAT.
Fig. 5 is a block diagram of the structure of the obtaining module 42 in the data receiving apparatus according to the embodiment of the present invention, and as shown in fig. 5, the obtaining module 42 includes: a first creating unit 52, a first obtaining unit 54, a first sending unit 56 and a receiving unit 58, which will be explained below.
A first creating unit 52 for creating a receiving port for receiving data; a first obtaining unit 54, connected to the first creating unit 52, configured to obtain information of a receiving port, where the information of the receiving port is used by the server to determine a port for receiving data; a first sending unit 56, connected to the first obtaining unit 54, configured to send, to the server through the relay server, a request message for requesting to obtain information of the sending port, where the request message carries information of the receiving port, and the information of the receiving port is used for the server to directly send data to the receiving port; and a receiving unit 58, connected to the first sending unit 56, configured to receive a response message returned by the server through the relay server according to the request message, where the response message carries information of the sending port.
Fig. 6 is a block diagram of a preferred structure of a data receiving apparatus according to an embodiment of the present invention, and as shown in fig. 6, the apparatus includes, in addition to all modules shown in fig. 4: the second sending module 62 is described below.
And a second sending module 62, connected to the first receiving module 46, for sending a termination request to the server through the relay server, where the termination request is used to request the server to stop sending data to the client.
In the above described embodiments and implementations of the data sending apparatus, the client may include an RTSP client, and the server may include an RTSP server; the information of the sending port can comprise a public network Internet Protocol (IP) address of the sending port and a NAT mapping public network port number; the information of the receiving port may include a public network internet protocol IP address of the receiving port and a NAT mapped public network port number.
The data transmission device is described from the perspective of a client, and an example and an embodiment of the data transmission device are described below from the perspective of a server.
Fig. 7 is a block diagram of a data transmission apparatus according to an embodiment of the present invention, which may be applied to a server, as shown in fig. 7, the apparatus including: a third transmitting module 72 and a fourth transmitting module 74, which will be described below.
A third sending module 72, configured to send information of a sending port, used for sending data, of a server to a client, where the client accesses a network through a first NAT, the information of the sending port is used for the client to send a penetration packet to the server through the first NAT, the penetration packet is used for the first NAT to record a mapping relationship between the information of the sending port and information of a receiving port, used for receiving data, of the client, and the mapping relationship is used for allowing data sent by the server to reach the client through the first NAT; and a fourth sending module 74 connected to the third sending module 72, configured to send data to the client, where the data reaches the client through the first NAT.
Fig. 8 is a block diagram of a third sending module 72 in the data sending apparatus according to the embodiment of the present invention, and as shown in fig. 8, the third sending module 72 further includes: a second acquiring unit 82, a second creating unit 84, a third acquiring unit 86, and a second transmitting unit 88, which will be described below.
A second obtaining unit 82, configured to obtain, by a relay server, a request message sent by a client for requesting to obtain information of a sending port, where the request message carries information of a receiving port; a second creating unit 84, connected to the second obtaining unit 82, for creating a sending port according to the request message; a third obtaining unit 86, connected to the second creating unit 84, for obtaining the information of the sending port; the second sending unit 88 is connected to the third obtaining unit 86, and is configured to send a response message to the client through the relay server, where the response message carries information of the sending port.
In an optional embodiment, in which the server accesses the network through the second NAT, the third sending module 72 may include: and sending information of the sending port to the relay server through the second NAT, wherein the information of the sending port is sent to the client by the relay server, the information of the sending port is used for the second NAT to record the mapping relation between the information of the sending port and the information of the receiving port, and the mapping relation is used for allowing data sent by the client to reach the server by penetrating through the second NAT.
Fig. 9 is a block diagram of a preferred structure of a data transmission apparatus according to an embodiment of the present invention, and as shown in fig. 9, the apparatus includes, in addition to all modules shown in fig. 7: a second receiving module 92 and a terminating module 94, which are described below.
A second receiving module 92, connected to the fourth sending module 74, for receiving the termination request sent by the client through the relay server; and a termination module 94, connected to the second receiving module 92, for stopping sending data to the client according to the termination request.
In the embodiment and implementation of the data sending module, the client may include an RTSP client, and the server may include an RTSP server; the information of the sending port can comprise a public network Internet Protocol (IP) address of the sending port and a NAT mapping public network port number; the information of the receiving port may include a public network internet protocol IP address of the receiving port and a NAT mapped public network port number.
It should be noted that the above modules may be implemented by software or hardware, and for the latter, the following form may be presented, but is not limited thereto, wherein the third sending module 72 and the fourth sending module 74 may be located in the same processor, or the third sending module 72 and the fourth sending module 74 may also be located in the first processor and the second processor, respectively.
The following takes an RTSP client and an RTSP server as examples to illustrate the present invention. Fig. 10 is a block diagram of a system structure according to an embodiment of the present invention, as shown in fig. 10, in order to implement direct access of an RTSP client and a server to a server in a networking scenario where the RTSP client and the server are respectively located behind different NAT devices, the RTSP client and the server first establish an RTSP session through a TCP relay server, a Simple traversal of User Data Protocol (UDP) of UDPover (STUN) server obtains respective Real-Time transport Protocol (RTP) and RTP Control Protocol (RTP Control Protocol, RTCP) port public network mapping addresses before RTSP SETUP message interaction, exchanges the respective RTP and RTCP public network mapping addresses in the RTSP SETUP message, and sends UDP traversal messages to the RTP and RTCP public network addresses of an opposite end to form records on the respective NAT devices, the RTP and RTCP messages of the opposite terminal can pass through the NAT equipment of the opposite terminal. The above method in this embodiment is described in detail below:
step 1): the RTSP client sends a selection request and a DESCRIBE request to the relay server, and the relay server forwards the RTSP server response;
step 2): the RTSP client creates a UDP port for receiving the RTP data message and acquires the public network IP address of the port and the NAT mapping public network port number through a STUN protocol;
step 3): the RTSP client sends a SETUP request to the relay server, and the RTP address is a receiving port public network address and a port number;
step 4), the RTSP server side creates an RTP sending port, and obtains the port public network address and NAT mapping public network port number through the STUN protocol;
step 5): the relay server forwards the SETUP response of the RTSP server, and the RTP address is the public network address and the port number of the sending end;
step 6): after the RTSP client sends and receives the PLAY response, the RTSP client sends an RTP UDP penetration message;
step 7): the RTSP server side sends a UDP data message to the client side;
step 8): and the RTSP client sends a TEARDOWN request to the relay server, and then the process is finished.
Compared with the related art, in the embodiment, the real-time streaming from point to point between the RTSP client and the server behind different NAT devices can be made possible. The real-time data transmission efficiency between the RTSP client and the server is improved.
In fig. 10, an RTSP client (such as a mobile phone or a tablet pc with a relevant Application (APP)) and an RTSP server (such as a camera capable of generating real-time audio/video streams) are located behind an NAT router, and the RTSP client located behind an NAT device wants to obtain the audio/video streams on an RTSP server located behind the NAT device, which can also be implemented according to the method provided in the embodiment of the present invention, and is specifically described as follows:
firstly, an RTSP relay server and a STUN server are deployed in a public network environment, wherein the relay server is used for forwarding requests and responses of a client and a server, and the STUN server is used for assisting the client and the server behind an NAT to traverse the NAT.
Fig. 11 is an interaction flowchart of an RTSP client and a server according to an embodiment of the present invention, and as shown in fig. 11, the process includes the following steps:
step S1102: based on the RTSP protocol, the client sends an OPTION, DESCRIBE request to the relay server, which forwards the client's request to the server and forwards the server's response to the client, as shown in messages 1-8 in fig. 11.
Step S1104: after receiving the DESCRIBE response, the RTSP client creates a UDP port for receiving the RTP data packet, obtains the public network IP address and NAT mapped public network port number of the port through the STUN protocol, such as message 9 in fig. 11, and publishes the obtained public network IP and port number in the next SETUP request.
Step S1106: after obtaining public network IP and NAT mapping public network port number through a STUN protocol, the RTSP client sends a SETUP request to a relay server, and an RTP address is a client receiving port public network address and port number; the relay server transmits the SETUP request to the server, the server establishes an RTP sending port, and acquires the public network address of the port and the NAT mapping public network port number through an STUN protocol; the server then sends a SETUP response to the relay server, where the RTP address in the SETUP response is the sender public network address and port number, and the relay server forwards the SETUP response to the client, as shown in messages 10-14 in fig. 11. So far, the client and the server already know the public network IP address and NAT mapping public network port number of the opposite terminal.
Step S1108: the RTSP client sends a PLAY request to the relay server, which forwards the PLAY request to the server, which replies a PLAY response, which forwards the PLAY response to the client, as shown in message 15-18 in fig. 11.
Step S1110: after receiving the PLAY response, the client sends an RTP UDP tunneling packet, such as the message 19 in fig. 11, to the server (the public network address of the sending end obtained in step S1306). After the message is sent, a record is formed on the NAT route connected with the client, and then the UDP data message sent from the server can traverse the NAT to reach the client.
So far, the RTSP client located behind the NAT can directly obtain the audio and video stream from the server also located behind the NAT.
In step S1112, the RTSP client may end the request for the audio/video stream by sending a TEARDOWN request to the relay server, as in messages 21-24 in fig. 11.
In summary, the technical scheme of the embodiment of the invention can achieve the following beneficial effects: the RTSP client side and the server side behind different NAT equipment can perform point-to-point real-time streaming transmission, the RTSP client side can acquire audio and video streams from the RTSP server side quickly and efficiently, communication between the RTSP client side and the server side is finished after the audio and video streams are acquired, and the utilization rate of system resources is improved.
It should be noted that, the above modules may be implemented by software or hardware, and for the latter, the following may be implemented, but not limited to: the modules are all positioned in the same processor; alternatively, the modules are respectively located in a plurality of processors.
In another embodiment, a storage medium is further provided, and optionally, in this embodiment, the storage medium may be configured to store program codes for performing the following steps:
s1, the client acquires information of a receiving port of the client and information of a sending port of the server, wherein the receiving port is used for the client to receive data, the sending port is used for the server to send data, and the client accesses the network through the first NAT;
s2, the client sends a penetration message to the server through the first NAT according to the information of the sending port, wherein the penetration message is used for the first NAT to record the mapping relation between the information of the sending port and the information of the receiving port, and the mapping relation is used for allowing the data sent by the server to reach the client through penetrating the first NAT;
and S3, the client receives the data which is sent by the server and reaches the client by penetrating the first NAT.
Optionally, in this embodiment, the storage medium may be further configured to store program codes for performing the following steps:
s1, the server sends information of a sending port of the server for sending data to the client, wherein the client accesses the network through a first NAT, the information of the sending port is used for the client to send a penetration message to the server through the first NAT, the penetration message is used for the first NAT to record the mapping relation between the information of the sending port and the information of a receiving port of the client for receiving data, and the mapping relation is used for allowing the data sent by the server to reach the client through the first NAT;
and S2, the server side sends data to the client side, wherein the data reach the client side through the first NAT.
Optionally, the storage medium stores the software, and the storage medium includes but is not limited to: a U-disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), an optical disk, a floppy disk, a removable hard disk, a magnetic disk, an erasable Memory, and other various media capable of storing program codes.
The above description is only an alternative embodiment of the present invention, and is not intended to limit the present invention, and various modifications and variations of the present invention may occur to those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (16)

1. A data receiving method, comprising:
the method comprises the steps that a client side obtains information of a receiving port of the client side and information of a sending port of a server side, wherein the receiving port is used for the client side to receive data, the sending port is used for the server side to send data, the client side is accessed to a network through a first Network Address Translator (NAT), the client side comprises a real-time streaming protocol (RTSP) client side, and the server side comprises an RTSP server side;
the client sends a penetration message to the server through the first NAT according to the information of the sending port, wherein the penetration message is used for the first NAT to record the mapping relationship between the information of the sending port and the information of the receiving port, and the mapping relationship is used for allowing the data sent by the server to reach the client through penetrating through the first NAT;
the client receives data which is sent by the server and reaches the client by penetrating through the first NAT;
the client acquires the information of the sending port of the server, and the method comprises the following steps:
the client sends a request message for requesting to acquire the information of the sending port to the server through a relay server, wherein the request message carries the information of the receiving port, and the information of the receiving port is used for the server to directly send data to the receiving port;
and the client receives a response message returned by the server through the relay server according to the request message, wherein the response message carries the information of the sending port.
2. The method of claim 1, wherein obtaining, by a client, information of a receiving port of the client and information of a sending port of a server comprises:
the client creates the receiving port;
and the client acquires the information of the receiving port.
3. The method of claim 1, wherein after the client receives the data sent by the server and reaching the client by penetrating through the first NAT, the method further comprises:
the client sends a termination request to the server through the relay server, wherein the termination request is used for requesting the server to stop sending data to the client.
4. The method of any one of claims 1 to 3, comprising at least one of:
the information of the sending port comprises a public network Internet Protocol (IP) address of the sending port and a NAT mapping public network port number;
the information of the receiving port comprises a public network Internet Protocol (IP) address of the receiving port and a NAT mapping public network port number.
5. A data transmission method, comprising:
the method comprises the steps that a server sends information of a sending port, used for sending data, of the server to a client, wherein the client is accessed to a network through a first Network Address Translator (NAT), the information of the sending port is used for the client to send a penetration message to the server through the first NAT, the penetration message is used for the first NAT to record the mapping relation between the information of the sending port and the information of a receiving port, used for receiving data, of the client, the mapping relation is used for allowing the data sent by the server to penetrate through the first NAT and reach the client, the client comprises a real-time streaming protocol (RTSP) client, and the server comprises an RTSP server;
the server side sends data to the client side, wherein the data reach the client side through the first NAT;
the sending, by the server, information of a sending port of the server for sending data to the client includes:
the server side acquires a request message which is sent by the client side and used for requesting to acquire the information of the sending port through a relay server, wherein the request message carries the information of the receiving port;
the server side creates the sending port according to the request message;
the server side acquires the information of the sending port;
and the server sends a response message to the client through the relay server, wherein the response message carries the information of the sending port.
6. The method of claim 5, wherein the server accesses the network through the second NAT, and the server sends, to the client, information of a sending port of the server for sending data, where the sending port is used to send data, where the information includes:
the server sends the information of the sending port to a relay server through the second NAT, wherein the information of the sending port is sent to the client by the relay server, the information of the sending port is used for the second NAT to record the mapping relation between the information of the sending port and the information of the receiving port, and the mapping relation is used for allowing the data sent by the client to reach the server by penetrating through the second NAT.
7. The method of claim 5, wherein after the server sends data to the client, the method further comprises:
the server receives a termination request sent by the client through a relay server;
and the server stops sending data to the client according to the termination request.
8. The method of any one of claims 5 to 7, comprising at least one of:
the information of the sending port comprises a public network Internet Protocol (IP) address of the sending port and a NAT mapping public network port number;
the information of the receiving port comprises a public network Internet Protocol (IP) address of the receiving port and a NAT mapping public network port number.
9. A data receiving apparatus, applied to a client, comprising:
the system comprises an acquisition module, a processing module and a processing module, wherein the acquisition module is used for acquiring information of a receiving port of a client and information of a sending port of a server, the receiving port is used for the client to receive data, the sending port is used for the server to send data, the client is accessed to a network through a first Network Address Translator (NAT), the client comprises a real-time streaming protocol (RTSP) client, and the server comprises an RTSP server;
a first sending module, configured to send a penetration packet to the server through the first NAT according to the information of the sending port, where the penetration packet is used for the first NAT to record a mapping relationship between the information of the sending port and the information of the receiving port, and the mapping relationship is used to allow data sent by the server to reach the client through penetrating through the first NAT;
a first receiving module, configured to receive data sent by the server and reaching the client through penetrating the first NAT
The acquisition module includes: a first transmitting unit and a receiving unit;
a first sending unit, configured to send, to the server through a relay server, a request message for requesting to obtain information of the sending port, where the request message carries information of the receiving port, and the information of the receiving port is used for the server to directly send data to the receiving port;
and the receiving unit is used for receiving a response message returned by the server through the relay server according to the request message, wherein the response message carries the information of the sending port.
10. The apparatus of claim 9, wherein the obtaining module further comprises:
a first creating unit configured to create the receiving port;
a first obtaining unit, configured to obtain information of the receiving port.
11. The apparatus of claim 9, further comprising:
and a second sending module, configured to send a termination request to the server through a relay server, where the termination request is used to request the server to stop sending data to the client.
12. The apparatus of any one of claims 9 to 11, comprising at least one of:
the information of the sending port comprises a public network Internet Protocol (IP) address of the sending port and a NAT mapping public network port number;
the information of the receiving port comprises a public network Internet Protocol (IP) address of the receiving port and a NAT mapping public network port number.
13. A data transmission device is applied to a server and comprises:
a third sending module, configured to send information of a sending port, used for sending data, of the server to a client, where the client accesses a network through a first network address translator NAT, the information of the sending port is used for the client to send a penetration packet to the server through the first NAT, the penetration packet is used for the first NAT to record a mapping relationship between the information of the sending port and information of a receiving port, used for receiving data, of the client, the mapping relationship is used for allowing data sent by the server to reach the client through the first NAT, the client includes a real-time streaming protocol RTSP client, and the server includes an RTSP server;
a fourth sending module, configured to send data to the client, where the data reaches the client through the first NAT;
the third sending module includes:
a second obtaining unit, configured to obtain, by a relay server, a request message sent by the client for requesting to obtain information of the sending port, where the request message carries information of the receiving port;
a second creating unit configured to create the sending port according to the request message;
a third obtaining unit, configured to obtain information of the sending port;
and a second sending unit, configured to send a response message to the client through the relay server, where the response message carries information of the sending port.
14. The apparatus of claim 13, wherein the server accesses the network through a second NAT, and the third sending module includes:
and sending the information of the sending port to a relay server through the second NAT, wherein the information of the sending port is sent to the client by the relay server, the information of the sending port is used for the second NAT to record the mapping relation between the information of the sending port and the information of the receiving port, and the mapping relation is used for allowing the data sent by the client to reach the server by penetrating through the second NAT.
15. The apparatus of claim 13, further comprising:
a second receiving module, configured to receive a termination request sent by the client through a relay server;
and the termination module is used for stopping sending data to the client according to the termination request.
16. The apparatus of any one of claims 13 to 15, comprising at least one of:
the information of the sending port comprises a public network Internet Protocol (IP) address of the sending port and a NAT mapping public network port number;
the information of the receiving port comprises a public network Internet Protocol (IP) address of the receiving port and a NAT mapping public network port number.
CN201510351869.5A 2015-06-23 2015-06-23 Data receiving and sending method and device Active CN106331195B (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN201510351869.5A CN106331195B (en) 2015-06-23 2015-06-23 Data receiving and sending method and device
PCT/CN2016/085880 WO2016206554A1 (en) 2015-06-23 2016-06-15 Method and device for receiving and transmitting data

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510351869.5A CN106331195B (en) 2015-06-23 2015-06-23 Data receiving and sending method and device

Publications (2)

Publication Number Publication Date
CN106331195A CN106331195A (en) 2017-01-11
CN106331195B true CN106331195B (en) 2020-01-14

Family

ID=57586696

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510351869.5A Active CN106331195B (en) 2015-06-23 2015-06-23 Data receiving and sending method and device

Country Status (2)

Country Link
CN (1) CN106331195B (en)
WO (1) WO2016206554A1 (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112543239B (en) * 2020-12-23 2022-06-24 杭州安司源科技有限公司 Progressive NAT (network Address translation) penetration method
CN114244908A (en) * 2021-11-05 2022-03-25 浙江蓝卓工业互联网信息技术有限公司 Cross-domain RTSP streaming media transmission method
CN114553745A (en) * 2022-01-21 2022-05-27 浙江航芯科技有限公司 Parent control device and method
CN114553414B (en) * 2022-03-03 2024-04-05 合肥浩瀚深度信息技术有限公司 Intranet penetration method and system based on HTTPS service

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101155185A (en) * 2006-09-26 2008-04-02 卡乐西堤企业股份有限公司 Interactive NAT traversing method of SIP communication protocol
CN101170687A (en) * 2007-11-28 2008-04-30 武汉烽火网络有限责任公司 Method for front recording order to penetrate NAT based on video monitoring
CN101557388A (en) * 2008-04-11 2009-10-14 中国科学院声学研究所 NAT traversing method based on combination of UPnP and STUN technologies
CN102035900A (en) * 2009-09-24 2011-04-27 日电(中国)有限公司 NAT (network address translation) traversal method, system and relay server by relay mode
CN103108054A (en) * 2011-11-11 2013-05-15 中国移动通信集团公司 Method for penetrating through transit server and corresponding server and terminal and system
CN103581350A (en) * 2012-07-25 2014-02-12 中国电信股份有限公司 Method, terminals, equipment and system for publishing Internet services across NAT
CN104144218A (en) * 2014-08-04 2014-11-12 三星电子(中国)研发中心 End-to-end connection building method and device

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100370794C (en) * 2004-03-10 2008-02-20 福州骏飞信息科技有限公司 UDP datagram communication transmission method
CN101729862B (en) * 2008-10-21 2011-12-28 中兴通讯股份有限公司 Method and system for passing media through NAT by using video monitoring system
US9137200B2 (en) * 2012-01-17 2015-09-15 Telefonaktiebolaget L M Ericsson (Publ) Ice based NAT traversal
TW201345237A (en) * 2012-04-27 2013-11-01 Univ Nat Taipei Technology Applied TCP traversal through NATs method in RTSP

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101155185A (en) * 2006-09-26 2008-04-02 卡乐西堤企业股份有限公司 Interactive NAT traversing method of SIP communication protocol
CN101170687A (en) * 2007-11-28 2008-04-30 武汉烽火网络有限责任公司 Method for front recording order to penetrate NAT based on video monitoring
CN101557388A (en) * 2008-04-11 2009-10-14 中国科学院声学研究所 NAT traversing method based on combination of UPnP and STUN technologies
CN102035900A (en) * 2009-09-24 2011-04-27 日电(中国)有限公司 NAT (network address translation) traversal method, system and relay server by relay mode
CN103108054A (en) * 2011-11-11 2013-05-15 中国移动通信集团公司 Method for penetrating through transit server and corresponding server and terminal and system
CN103581350A (en) * 2012-07-25 2014-02-12 中国电信股份有限公司 Method, terminals, equipment and system for publishing Internet services across NAT
CN104144218A (en) * 2014-08-04 2014-11-12 三星电子(中国)研发中心 End-to-end connection building method and device

Also Published As

Publication number Publication date
CN106331195A (en) 2017-01-11
WO2016206554A1 (en) 2016-12-29

Similar Documents

Publication Publication Date Title
CN109274634B (en) Multimedia communication method and device, and storage medium
TWI408936B (en) Network traversal method and network communication system
CN102984289B (en) Promote the method that penetrates of NAT and mobile device
CN108259542B (en) Resource transmission method and device
CN106331195B (en) Data receiving and sending method and device
US20130308628A1 (en) Nat traversal for voip
CN104660952B (en) Video conference communication method and system
CN103957287A (en) Internet of things device P2P connection method based on NAT penetration adapter
CN103107983B (en) Data management method of network system and related system thereof
US9049122B2 (en) Bandwidth probing messages
US8724630B2 (en) Method and system for implementing network intercommunication
CN106559504B (en) Address translation method and device
CN108306986B (en) Multi-type media data network address conversion traversing method, terminal and system
CN113630439B (en) Real-time communication RTC connection method, server and storage medium
CN106453683A (en) Method for centralized access management of cameras
US20230291706A1 (en) Method for accessing network, media gateway, electronic device and storage medium
US7542475B2 (en) Communication between users located behind a NAT device
US9413590B2 (en) Method for management of a secured transfer session through an address translation device, corresponding server and computer program
CN106878481B (en) Method, device and system for acquiring Internet Protocol (IP) address
JP2007049499A (en) Communication method and apparatus
CN104994067B (en) SIP network accesses the system and method for RTSP monitoring networks
KR20140092630A (en) User's device, communication server and control method thereof
EP3079328A1 (en) Media resource sharing method, shared server and shared system
US20120047271A1 (en) Network address translation device and method of passing data packets through the network address translation device
CN104378301B (en) A kind of data processing method and data processing equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant