[go: up one dir, main page]

CN113411367B - Method, device, equipment, system and storage medium for establishing connection of monitoring equipment - Google Patents

Method, device, equipment, system and storage medium for establishing connection of monitoring equipment Download PDF

Info

Publication number
CN113411367B
CN113411367B CN202010186648.8A CN202010186648A CN113411367B CN 113411367 B CN113411367 B CN 113411367B CN 202010186648 A CN202010186648 A CN 202010186648A CN 113411367 B CN113411367 B CN 113411367B
Authority
CN
China
Prior art keywords
port
router
client
connection
request
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
CN202010186648.8A
Other languages
Chinese (zh)
Other versions
CN113411367A (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.)
Zhejiang Uniview Technologies Co Ltd
Original Assignee
Zhejiang Uniview Technologies Co Ltd
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 Zhejiang Uniview Technologies Co Ltd filed Critical Zhejiang Uniview Technologies Co Ltd
Priority to CN202010186648.8A priority Critical patent/CN113411367B/en
Publication of CN113411367A publication Critical patent/CN113411367A/en
Application granted granted Critical
Publication of CN113411367B publication Critical patent/CN113411367B/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
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/141Setup of application sessions
    • 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
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/60Scheduling or organising the servicing of application requests, e.g. requests for application data transmissions using the analysis and optimisation of the required network resources
    • H04L67/63Routing a service request depending on the request content or context

Landscapes

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

Abstract

本发明公开了一种监控设备建立连接的方法、装置、设备、系统及计算机可读存储介质;在本方案中,客户端与监控设备建立连接时,如果监控设备通过原始端口向客户端返回请求响应后,未收到客户端发送的下一步请求,则监控设备通过将备用端口替换原始端口,自动修改路由器与监控设备的映射关系,从而使得响应请求可通过修改后的映射关系发送至客户端,以成功建立客户端与监控设备的连接,这样客户端在获取监控设备的实况及回放数据时,便不会因路由器禁用端口而导致出现黑屏现象;并且,这种取消原始端口映射关系保留路由器内部端口的方式,可保证NAT的组网正常,不会出现由于内部端口变更导致的异常断流问题。

Figure 202010186648

The invention discloses a method, device, device, system and computer-readable storage medium for establishing a connection between monitoring equipment; After the response, if the next request sent by the client is not received, the monitoring device automatically modifies the mapping relationship between the router and the monitoring device by replacing the original port with the alternate port, so that the response request can be sent to the client through the modified mapping relationship. , in order to successfully establish the connection between the client and the monitoring device, so that when the client obtains the live and playback data of the monitoring device, the black screen will not appear due to the port being disabled by the router; and this cancellation of the original port mapping relationship retains the router. The internal port method can ensure that the NAT networking is normal, and there will be no abnormal flow interruption caused by the change of the internal port.

Figure 202010186648

Description

监控设备建立连接的方法、装置、设备、系统及存储介质Method, device, device, system and storage medium for establishing connection for monitoring equipment

技术领域technical field

本发明涉及数据交互技术领域,更具体地说,涉及一种监控设备建立连接的方法、装置、设备、系统及计算机可读存储介质。The present invention relates to the technical field of data interaction, and more particularly, to a method, apparatus, device, system and computer-readable storage medium for establishing a connection between monitoring equipment.

背景技术Background technique

目前,在监控领域中,常用的标准组网是NVR(Network Video Recorder,网络视频录像机)和IPC(IP CAMERA,网络摄像机)在局域网下,通过路由器端口映射到外网,通过RTSP(Real Time Streaming Protocol,实时流传输协议)进行音视频码流传输,供用户远程访问使用,参见图1,为现有技术中的常见监控组网示意图,通过图1可见,NVR和IPC通过路由器与广域网的云服务网站和手机客户端进行音视频交互。但是,目前部分常见路由器会自动禁用NAT(Network Address Translation,网络地址转换)内设备的部分端口穿NAT交互,如某些路由器会自动禁用NAT内设备的554端口穿NAT交互,此时会导致RTSP无法穿NAT传输,用户查看摄像机和录像机的实况及回放时,会出现黑屏现象,无法正常使用,并且用户无法得知是由于路由器禁用端口导致,也无法知道如何规避该问题。At present, in the field of monitoring, the commonly used standard networking is NVR (Network Video Recorder, network video recorder) and IPC (IP CAMERA, network camera) under the local area network, through the router port mapping to the external network, through RTSP (Real Time Streaming) Protocol, real-time streaming protocol) to transmit audio and video streams for users to access remotely The service website and the mobile client perform audio and video interaction. However, at present, some common routers will automatically disable some ports of devices in NAT (Network Address Translation) from interacting through NAT. For example, some routers will automatically disable the 554 ports of devices in NAT from interacting through NAT, which will lead to RTSP. It cannot transmit through NAT. When users view the live and playback of cameras and recorders, there will be a black screen phenomenon, which cannot be used normally, and users cannot know that it is caused by the disabled port of the router, nor can they know how to avoid this problem.

发明内容SUMMARY OF THE INVENTION

本发明的目的在于提供一种监控设备建立连接的方法、装置、设备、系统及计算机可读存储介质,以避免因路由器禁用端口,而导致无法通过端口进行数据传输的问题。The purpose of the present invention is to provide a method, device, device, system and computer-readable storage medium for establishing a connection between monitoring equipment, so as to avoid the problem that data transmission cannot be performed through the port due to the port being disabled by the router.

为实现上述目的,本发明提供的一种监控设备建立连接的方法,包括:To achieve the above purpose, a method for establishing a connection for a monitoring device provided by the present invention includes:

通过内部端口接收路由器转发的连接请求,所述连接请求为客户端通过外部端口发送至路由器,所述内部端口与所述外部端口具有映射关系;Receive a connection request forwarded by the router through an internal port, where the connection request is sent by the client to the router through an external port, and the internal port has a mapping relationship with the external port;

将与所述连接请求对应的响应请求通过所述内部端口发送至所述路由器,以使所述路由器通过所述外部端口将所述响应请求转发至所述客户端;sending a response request corresponding to the connection request to the router through the internal port, so that the router forwards the response request to the client through the external port;

若在发送完所述响应请求的第一预定时长内,未接收所述客户端发送的其他请求,则在所述路由器取消所述内部端口与所述外部端口的映射关系,并建立所述备用端口与所述外部端口的映射关系;If no other request sent by the client is received within the first predetermined period of time after the response request is sent, the router cancels the mapping relationship between the internal port and the external port, and establishes the backup the mapping relationship between the port and the external port;

将所述响应请求通过所述备用端口发送至所述路由器,以使所述路由器通过所述外部端口将所述响应请求转发至所述客户端,从而建立所述监控设备与所述客户端的连接。Sending the response request to the router through the alternate port, so that the router forwards the response request to the client through the external port, thereby establishing a connection between the monitoring device and the client .

其中,所述通过内部端口接收路由器转发的连接请求,包括:Wherein, receiving the connection request forwarded by the router through the internal port includes:

通过内部端口接收路由器转发的建立RTSP连接的OPTIONS请求。Receive the OPTIONS request to establish an RTSP connection forwarded by the router through the internal port.

其中,在所述路由器取消所述内部端口与所述外部端口的映射关系,并建立所述备用端口与所述外部端口的映射关系,包括:Wherein, canceling the mapping relationship between the internal port and the external port at the router, and establishing the mapping relationship between the standby port and the external port, includes:

向所述路由器发送映射关系取消指令,所述映射关系取消指令用于取消所述内部端口与所述外部端口的映射关系;sending a mapping relationship cancellation instruction to the router, where the mapping relationship cancellation instruction is used to cancel the mapping relationship between the internal port and the external port;

若接收到所述路由器发送的映射关系取消成功的提示信息,则向所述路由器发送映射关系创建指令,所述映射关系创建指令用于建立所述备用端口与所述外部端口的映射关系。If the prompt information sent by the router indicating that the mapping relationship is canceled successfully is received, a mapping relationship creation instruction is sent to the router, and the mapping relationship creation instruction is used to establish the mapping relationship between the standby port and the external port.

其中,将所述响应请求通过所述备用端口发送至所述路由器,包括:Wherein, sending the response request to the router through the standby port includes:

若接收到所述路由器发送的映射关系建立成功的提示信息,则将所述响应请求通过所述备用端口发送至所述路由器。If the prompt information sent by the router that the mapping relationship is established successfully is received, the response request is sent to the router through the standby port.

其中,若在发送完所述响应请求的第一预定时长内,未接收所述客户端发送的其他请求,则所述方法还包括:Wherein, if no other requests sent by the client are received within the first predetermined period of time after the response request is sent, the method further includes:

通过所述路由器向所述客户端发送保活命令;sending a keep-alive command to the client through the router;

判断第二预定时长内,是否接收到所述客户端通过所述路由器转发的保活响应命令;Determine whether a keep-alive response command forwarded by the client through the router is received within a second predetermined period of time;

若是,则执行所述在所述路由器取消所述内部端口与所述外部端口的映射关系,并建立所述备用端口与所述外部端口的映射关系的步骤。If so, execute the step of canceling the mapping relationship between the internal port and the external port on the router, and establishing a mapping relationship between the standby port and the external port.

为实现上述目的,本发明进一步提供一种监控设备建立连接的装置,包括:In order to achieve the above object, the present invention further provides a device for establishing a connection between monitoring equipment, including:

接收模块,用于通过内部端口接收路由器转发的连接请求,所述连接请求为客户端通过外部端口发送至所述路由器,所述内部端口与所述外部端口具有映射关系;a receiving module, configured to receive a connection request forwarded by a router through an internal port, where the connection request is sent by a client to the router through an external port, and the internal port has a mapping relationship with the external port;

第一发送模块,用于将与所述连接请求对应的响应请求通过所述内部端口发送至所述路由器,以使所述路由器通过所述外部端口将所述响应请求转发至所述客户端;a first sending module, configured to send a response request corresponding to the connection request to the router through the internal port, so that the router forwards the response request to the client through the external port;

端口替换模块,用于在发送完所述响应请求的第一预定时长内,未接收所述客户端发送的其他请求时,在所述路由器取消所述内部端口与所述外部端口的映射关系,并建立所述备用端口与所述外部端口的映射关系;A port replacement module, configured to cancel the mapping relationship between the internal port and the external port when the router does not receive other requests sent by the client within the first predetermined period of time after the response request is sent, and establishing a mapping relationship between the standby port and the external port;

第二发送模块,用于将所述响应请求通过所述备用端口发送至所述路由器,以使所述路由器通过所述外部端口将所述响应请求转发至所述客户端,从而建立所述监控设备与所述客户端的连接。A second sending module, configured to send the response request to the router through the standby port, so that the router forwards the response request to the client through the external port, thereby establishing the monitoring The connection of the device to the client.

其中,本装置还包括:Wherein, the device also includes:

第三发送模块,用于通过所述路由器向所述客户端发送保活命令;a third sending module, configured to send a keep-alive command to the client through the router;

判断模块,用于判断第二预定时长内,是否接收到所述客户端通过所述路由器转发的保活响应命令;a judging module for judging whether a keep-alive response command forwarded by the client through the router is received within a second predetermined period of time;

所述端口替换模块,用于在第二预定时长内接收到所述客户端通过所述路由器转发的保活响应命令时,在所述路由器取消所述内部端口与所述外部端口的映射关系,并建立所述备用端口与所述外部端口的映射关系。The port replacement module is configured to cancel the mapping relationship between the internal port and the external port when the router cancels the mapping relationship between the internal port and the external port when receiving the keep-alive response command forwarded by the client through the router within a second predetermined period of time, and establishing a mapping relationship between the standby port and the external port.

为实现上述目的,本发明进一步提供一种电子设备,包括:To achieve the above object, the present invention further provides an electronic device, comprising:

存储器,用于存储计算机程序;memory for storing computer programs;

处理器,用于执行所述计算机程序时实现上述的监控设备建立连接的方法的步骤。The processor is configured to implement the steps of the above-mentioned method for establishing a connection for a monitoring device when executing the computer program.

为实现上述目的,本发明进一步提供一种连接建立系统,包括:客户端、路由器、以及上述的电子设备。In order to achieve the above object, the present invention further provides a connection establishment system, including: a client, a router, and the above electronic device.

为实现上述目的,本发明进一步提供一种计算机可读存储介质,所述计算机可读存储介质上存储有计算机程序,所述计算机程序被处理器执行时实现上述的监控设备建立连接的方法的步骤。In order to achieve the above object, the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the above-mentioned method for establishing a connection between a monitoring device and a monitoring device are implemented. .

通过以上方案可知,本发明实施例提供的一种监控设备建立连接的方法,包括:通过内部端口接收路由器转发的连接请求,所述连接请求为客户端通过外部端口发送至所述路由器,所述内部端口与所述外部端口具有映射关系;将与所述连接请求对应的响应请求通过所述内部端口发送至所述路由器,以使所述路由器通过所述外部端口将所述响应请求转发至所述客户端;若在发送完所述响应请求的第一预定时长内,未接收所述客户端发送的其他请求,则在所述路由器取消所述内部端口与所述外部端口的映射关系,并建立所述备用端口与所述外部端口的映射关系;将所述响应请求通过所述备用端口发送至所述路由器,以使所述路由器通过所述外部端口将所述响应请求转发至所述客户端,从而建立所述监控设备与所述客户端的连接。As can be seen from the above solutions, a method for establishing a connection for a monitoring device provided by an embodiment of the present invention includes: receiving a connection request forwarded by a router through an internal port, where the connection request is sent by a client to the router through an external port, and the The internal port has a mapping relationship with the external port; the response request corresponding to the connection request is sent to the router through the internal port, so that the router forwards the response request to the router through the external port. If no other request sent by the client is received within the first predetermined period of time after sending the response request, the router will cancel the mapping relationship between the internal port and the external port, and establishing a mapping relationship between the standby port and the external port; sending the response request to the router through the standby port, so that the router forwards the response request to the client through the external port terminal, thereby establishing the connection between the monitoring device and the client.

可见,在本方案中,客户端与监控设备建立连接时,如果监控设备通过原始端口向客户端返回请求响应后,未收到客户端发送的下一步请求,则监控设备通过将备用端口替换原始端口,自动修改路由器与监控设备的映射关系,从而使得响应请求可通过修改后的映射关系发送至客户端,以成功建立客户端与监控设备的连接,这样客户端在获取监控设备的实况及回放数据时,便不会因路由器禁用端口而导致出现黑屏现象;并且,这种取消原始端口映射关系保留路由器内部端口的方式,可保证NAT的组网正常,不会出现由于内部端口变更导致的异常断流问题。It can be seen that in this solution, when the client establishes a connection with the monitoring device, if the monitoring device does not receive the next request sent by the client after returning a request response to the client through the original port, the monitoring device replaces the original port with the original port. Port, automatically modify the mapping relationship between the router and the monitoring device, so that the response request can be sent to the client through the modified mapping relationship to successfully establish the connection between the client and the monitoring device, so that the client can obtain the live and playback of the monitoring device. In addition, this method of canceling the original port mapping relationship and retaining the internal ports of the router can ensure that the NAT networking is normal, and there will be no abnormality caused by internal port changes. Outage problem.

本发明还公开了一种监控设备建立连接的装置、设备、系统及计算机可读存储介质,同样能实现上述技术效果。The invention also discloses an apparatus, equipment, system and computer-readable storage medium for establishing a connection between monitoring equipment, which can also achieve the above technical effects.

附图说明Description of drawings

为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to explain the embodiments of the present invention or the technical solutions in the prior art more clearly, the following briefly introduces the accompanying drawings that need to be used in the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are only These are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can also be obtained according to these drawings without creative efforts.

图1为现有技术中的常见监控组网示意图;1 is a schematic diagram of a common monitoring network in the prior art;

图2为本发明实施例公开的一种监控设备建立连接的系统结构示意图;2 is a schematic structural diagram of a system for establishing a connection between a monitoring device disclosed in an embodiment of the present invention;

图3为本发明实施例公开的一种监控设备建立连接的方法流程示意图;3 is a schematic flowchart of a method for establishing a connection for a monitoring device disclosed in an embodiment of the present invention;

图4为本发明实施例公开的另一种监控设备建立连接的方法流程示意图;4 is a schematic flowchart of another method for establishing a connection for a monitoring device disclosed in an embodiment of the present invention;

图5为本发明实施例公开的整体方案流程图;FIG. 5 is a flow chart of an overall solution disclosed in an embodiment of the present invention;

图6为本发明实施例公开的穿NAT交互时序图;6 is a sequence diagram of an interaction through NAT disclosed in an embodiment of the present invention;

图7为本发明实施例公开的一种监控设备建立连接的装置结构示意图;7 is a schematic structural diagram of an apparatus for establishing a connection for a monitoring device disclosed in an embodiment of the present invention;

图8为本发明实施例公开的一种电子设备结构示意图。FIG. 8 is a schematic structural diagram of an electronic device disclosed in an embodiment of the present invention.

具体实施方式Detailed ways

下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, but not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.

目前,路由器会禁止部分端口穿NAT交互,这会导致数据无法穿NAT传输,如:客户端获取NAT内的监控设备的音视频数据时,由于RTSP的554端口禁用,音视频流无法穿NAT传输,在客户端处会出现实况及回放黑屏的状况。但是,实际操作的终端用户无法感知是因为路由器禁用554端口导致该问题,也无法得知修改RTSP端口可以规避该问题,同时直接修改RTSP端口,不符合标准的协议,可能存在一致性和兼容性问题,也会导致NAT的RTSP出现异常断流。At present, the router will prohibit some ports from interacting through NAT, which will cause data to fail to pass through NAT. For example, when the client obtains the audio and video data of the monitoring device in the NAT, because the RTSP port 554 is disabled, the audio and video streams cannot be transmitted through NAT. , the actual situation and playback black screen will appear on the client side. However, the actual end user cannot perceive the problem because the router disables port 554, and cannot know that modifying the RTSP port can avoid this problem. At the same time, modifying the RTSP port directly, which does not conform to the standard protocol, may exist consistency and compatibility The problem will also cause abnormal interruption of RTSP of NAT.

因此在本申请中,公开了一种监控设备建立连接的方法、装置、设备、系统及计算机可读存储介质,通过本方案,可以使NAT内的监控设备既可以规避由路由器禁用554等端口导致实况、回放功能不可用问题,同时保证NAT内设备本身的554端口不发生变化,保证NAT的组网正常,不会出现由于RTSP端口变更导致的异常断流问题。Therefore, in this application, a method, device, device, system and computer-readable storage medium for establishing a connection between monitoring equipment are disclosed. Through this solution, the monitoring equipment in the NAT can be prevented from being caused by the router disabling ports such as 554. The live and playback functions are unavailable, and the 554 port of the device itself in the NAT does not change, which ensures that the NAT networking is normal, and there will be no abnormal flow interruption caused by the change of the RTSP port.

为了便于理解,下面对本申请的技术方案所适用的系统架构进行介绍,在本申请中,该系统可以包括客户端、路由器及电子设备,在本实施例中,电子设备以监控设备为例进行说明,参见图2,为本发明实施例公开的一种监控设备建立连接的系统结构示意图。通过图1可以看出,本系统可以包括客户端11、路由器12及监控设备13。For ease of understanding, the following introduces the system architecture to which the technical solutions of the present application are applicable. In the present application, the system may include a client, a router and an electronic device. In this embodiment, the electronic device is described by taking a monitoring device as an example. 2 , which is a schematic structural diagram of a system for establishing a connection between a monitoring device disclosed in an embodiment of the present invention. As can be seen from FIG. 1 , the system may include a client 11 , a router 12 and a monitoring device 13 .

其中,客户端11用于将连接请求通过外部端口发送至路由器12,该客户端11可以包括但不限于:智能手机、平板电脑、笔记本电脑、台式电脑等或智能穿戴式设备等。The client 11 is used to send a connection request to the router 12 through an external port, and the client 11 may include, but is not limited to, a smart phone, a tablet computer, a notebook computer, a desktop computer, or a smart wearable device.

路由器12用于实现客户端11与监控设备13之间的数据交互,将客户端发送的连接请求转发至监控设备13。The router 12 is used to realize data interaction between the client 11 and the monitoring device 13 , and forward the connection request sent by the client to the monitoring device 13 .

监控设备13用于通过内部端口接收连接请求,并将与该连接请求对应的响应请求通过内部端口发送至路由器12,路由器12再通过外部端口将该响应请求转发至客户端11;并且,若在发送完该响应请求的第一预定时长内,监控设备13未接收客户端11发送的其他请求,则通过备用端口替换内部端口,并在路由器13建立备用端口与外部端口的映射关系;然后再将响应请求通过备用端口发送至路由器13,以使路由器13通过外部端口将响应请求转发至客户端,从而建立所述监控设备与所述客户端的连接。并且,本申请中的监控设备具体可以为NVR、IPC等任意视频采集设备。The monitoring device 13 is configured to receive the connection request through the internal port, and send the response request corresponding to the connection request to the router 12 through the internal port, and the router 12 then forwards the response request to the client 11 through the external port; Within the first predetermined period of time after sending the response request, the monitoring device 13 does not receive other requests sent by the client 11, then replaces the internal port with the spare port, and establishes a mapping relationship between the spare port and the external port on the router 13; The response request is sent to the router 13 through the spare port, so that the router 13 forwards the response request to the client through the external port, thereby establishing the connection between the monitoring device and the client. Moreover, the monitoring device in this application may specifically be any video capture device such as NVR and IPC.

参见图3,本发明实施例提供的一种监控设备建立连接的方法流程示意图;该方法具体可以包括:Referring to FIG. 3 , a schematic flowchart of a method for establishing a connection for a monitoring device provided by an embodiment of the present invention may specifically include:

S101、通过内部端口接收路由器转发的连接请求,连接请求为客户端通过外部端口发送至路由器,内部端口与外部端口具有映射关系;S101, receiving the connection request forwarded by the router through the internal port, the connection request is sent by the client to the router through the external port, and the internal port and the external port have a mapping relationship;

可以理解的是,本申请中的内部端口和外部端口为具有映射关系的两个端口,客户端向监控设备发送连接请求时,需要将连接请求发送至路由器的外部端口,路由器通过内部端口与外部端口的映射关系,将连接请求通过内部端口转发至监控设备。It can be understood that the internal port and the external port in this application are two ports with a mapping relationship. When the client sends a connection request to the monitoring device, it needs to send the connection request to the external port of the router, and the router communicates with the external port through the internal port. Port mapping relationship, forward connection requests to monitoring devices through internal ports.

具体来说,如果客户端和监控设备之间通过RTSP进行音视频码流传输,那么该连接请求为通过内部端口接收的路由器转发的建立RTSP连接的OPTIONS请求。在本实施例中,可以设定RTSP内部端口为554,设定RTSP外部端口为8554,那么该连接请求就是通过8554端口发给路由器,路由器通过554端口将连接请求发送至监控设备。Specifically, if the audio and video streams are transmitted between the client and the monitoring device through RTSP, the connection request is an OPTIONS request for establishing an RTSP connection that is forwarded by the router and received through the internal port. In this embodiment, the RTSP internal port can be set to 554, and the RTSP external port can be set to 8554, then the connection request is sent to the router through port 8554, and the router sends the connection request to the monitoring device through port 554.

S102、将与连接请求对应的响应请求通过内部端口发送至路由器,以使路由器通过外部端口将响应请求转发至客户端;S102, sending the response request corresponding to the connection request to the router through the internal port, so that the router forwards the response request to the client through the external port;

在本实施例中,监控设备接收到连接请求后,会将与该连接请求对应的响应请求通过内部端口、外部端口发送至客户端;如果路由器未禁用该内部端口,该响应请求会通过路由器发送至客户端,客户端则会继续向监控设备下发其他连接请求;如果路由器禁用了该内部端口,那么客户端便不会收到该响应请求。具体来说,如果该连接请求为建立RTSP连接的OPTIONS请求,由于该OPTIONS请求是用来询问监控设备可用的方法,因此,监控设备向客户端回复的响应命令中,会包括给监控设备可用的方法,如:OPTIONS、DESCRIBE、SETUP、TEARDOWN、PLAY等等。In this embodiment, after receiving the connection request, the monitoring device will send the response request corresponding to the connection request to the client through the internal port and the external port; if the router does not disable the internal port, the response request will be sent through the router To the client, the client will continue to send other connection requests to the monitoring device; if the router disables the internal port, the client will not receive the response request. Specifically, if the connection request is an OPTIONS request for establishing an RTSP connection, since the OPTIONS request is used to inquire about the available methods of the monitoring device, the response command returned by the monitoring device to the client will include the available methods for the monitoring device. Methods, such as: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, etc.

S103、若在发送完响应请求的第一预定时长内,未接收客户端发送的其他请求,则在路由器取消内部端口与外部端口的映射关系,并建立备用端口与外部端口的映射关系;S103, if other requests sent by the client are not received within the first predetermined period of time after sending the response request, cancel the mapping relationship between the internal port and the external port at the router, and establish the mapping relationship between the standby port and the external port;

可以理解的是,本申请在建立RTSP连接时,客户端首先会向监控设备发送OPTIONS连接请求,客户端获取到响应请求中的参数后,会向监控设备发送其他的请求,例如:DESCRIBE请求(为了得到会话描述信息)、SETUP请求(用来提醒服务器建立会话,并确定传输模式)等等。但是,若由于路由器禁用部分端口,导致客户端收不到监控设备发送的响应请求,这时客户端便不会向监控设备发送其他请求。It can be understood that when establishing an RTSP connection in this application, the client first sends an OPTIONS connection request to the monitoring device, and after the client obtains the parameters in the response request, it will send other requests to the monitoring device, such as: DESCRIBE request ( In order to get the session description information), SETUP request (used to remind the server to establish a session, and determine the transmission mode) and so on. However, if the client cannot receive the response request sent by the monitoring device because the router disables some ports, the client will not send other requests to the monitoring device.

因此,监控设备为了保证路由器不会因为端口禁用而导致连接建立失败,会在向客户端发送响应请求之后开始计时,判断在第一预定时长内是否接收到客户端发送的其他请求;如果接收到其他请求,则说明路由器未禁用端口,这时便不需要执行后续流程,如果没有接收到其他请求,则说明路由器可能因为禁用端口而导致响应请求未发送至客户端,这时本方案可以通过备用端口替换内部端口,即:取消原内部端口与外部端口的映射关系,并建立备用端口与外部端口的映射关系,并通过重新建立的端口映射关系,再次通过路由器向客户端发送响应请求。例如:若RTSP内部端口为554,外部端口为8554,554和8554具有映射关系,在建立RTSP时,是通过554端口和8554端口进行请求的发送;若通过555端口替换554端口,则需要取消554端口和8554端口的映射关系,并建立555端口和8554端口的映射关系,通过555端口和8554端口进行请求的发送。Therefore, in order to ensure that the router will not fail to establish a connection due to port disabling, the monitoring device will start timing after sending a response request to the client to determine whether other requests sent by the client are received within the first predetermined period of time; For other requests, it means that the router has not disabled the port. In this case, there is no need to perform the subsequent process. If no other request is received, it means that the router may not send the response request to the client because the port is disabled. The port replaces the internal port, that is, cancel the mapping relationship between the original internal port and the external port, establish the mapping relationship between the standby port and the external port, and send a response request to the client through the router again through the re-established port mapping relationship. For example: if the internal port of RTSP is 554 and the external port is 8554, 554 and 8554 have a mapping relationship. When establishing RTSP, the request is sent through port 554 and port 8554; if port 554 is replaced by port 555, 554 needs to be cancelled. The mapping relationship between port and port 8554 is established, and the mapping relationship between port 555 and port 8554 is established, and requests are sent through port 555 and port 8554.

S104、将响应请求通过备用端口发送至路由器,以使路由器通过外部端口将响应请求转发至客户端,从而建立监控设备与客户端的连接。S104: Send the response request to the router through the standby port, so that the router forwards the response request to the client through the external port, thereby establishing a connection between the monitoring device and the client.

在本申请中,通过备用端口替换内部端口后,会再次通过重新建立的备用端口和外部端口的映射关系,向客户端发送响应请求,完成监控设备与客户端的RTSP连接的建立,并传输音视频流。需要说明的是,如果通过备用端口替换内部端口后,还是不能接收到客户端发送的其他请求,这时说明并不是因为路由器禁用端口导致的指令传输中断,可能是因为其他原因导致该问题,如网络故障问题、设备故障问题等等,这时可将该问题上报管理员,通过管理员进行人工修复。In this application, after replacing the internal port with the alternate port, a response request will be sent to the client again through the re-established mapping relationship between the alternate port and the external port to complete the establishment of the RTSP connection between the monitoring device and the client, and transmit audio and video flow. It should be noted that if the internal port is replaced by the spare port, other requests sent by the client cannot be received. At this time, it means that the command transmission is not interrupted due to the port being disabled by the router, but may be caused by other reasons, such as Network failure, equipment failure, etc., you can report the problem to the administrator, and the administrator can repair it manually.

综上可以看出,客户端与监控设备建立连接时,如果监控设备通过原始端口向客户端返回请求响应后,未收到客户端发送的下一步请求,则监控设备通过将备用端口替换原始端口,自动修改路由器与监控设备的映射关系从而使得响应请求可通过修改后的映射关系发送至客户端,以成功建立客户端与监控设备的连接,这样客户端在获取监控设备的实况及回放数据时,便不会因路由器禁用端口而导致出现黑屏现象;并且,这种取消原始端口映射关系保留路由器内部端口的方式,可保证NAT的组网正常,不会出现由于内部端口变更导致的异常断流问题。It can be seen from the above that when the client establishes a connection with the monitoring device, if the monitoring device does not receive the next request sent by the client after returning a request response to the client through the original port, the monitoring device will replace the original port with the alternate port. , automatically modify the mapping relationship between the router and the monitoring device so that the response request can be sent to the client through the modified mapping relationship, so as to successfully establish the connection between the client and the monitoring device, so that when the client obtains the live and playback data of the monitoring device , there will be no black screen phenomenon caused by the router disabling the port; in addition, this method of canceling the original port mapping relationship and retaining the internal port of the router can ensure that the NAT networking is normal, and there will be no abnormal flow interruption caused by the change of the internal port. question.

参见图4,本发明实施例提供的另一种监控设备建立连接的方法流程示意图;需要说明的是,本实施例与上一实施例的相同之处可以相互参照,在此便不再赘述;在本实施例中,该方法具体可以包括:Referring to FIG. 4 , another schematic flowchart of a method for establishing a connection for a monitoring device provided by an embodiment of the present invention; it should be noted that the similarities between this embodiment and the previous embodiment can be referred to each other, and details are not repeated here; In this embodiment, the method may specifically include:

S201、通过内部端口接收路由器转发的连接请求,连接请求为客户端通过外部端口发送至路由器,内部端口与外部端口具有映射关系;S201, receiving the connection request forwarded by the router through the internal port, the connection request is sent by the client to the router through the external port, and the internal port and the external port have a mapping relationship;

S202、将与连接请求对应的响应请求通过内部端口发送至路由器,以使路由器通过外部端口将响应请求转发至客户端;S202, sending the response request corresponding to the connection request to the router through the internal port, so that the router forwards the response request to the client through the external port;

S203、若在发送完响应请求的第一预定时长内,未接收客户端发送的其他请求,则通过路由器向客户端发送保活命令;S203. If no other requests sent by the client are received within the first predetermined time period after the response request is sent, send a keep-alive command to the client through the router;

S204、判断第二预定时长内,是否接收到客户端通过路由器转发的保活响应命令;若是,则执行S205;若否,则结束流程;S204, determine whether the keep-alive response command forwarded by the client through the router is received within the second predetermined duration; if so, execute S205; if not, end the process;

可以理解的是,如果监控设备在第一预定时长内未接收到客户端发送的其他请求,有可能是因为端口禁用问题导致的,也有可能是因为网络故障或者设备故障问题导致的。因此在本实施例中,为了避免在修改端口映射关系后,依然不能通过修改后的端口映射关系发送响应请求,从而导致端口映射关系的无效修改,可以在修改映射关系之前,通过向客户端发送保活命令,探测网络或者客户端是否故障,从而排除其他可能出现的问题。It can be understood that, if the monitoring device does not receive other requests sent by the client within the first predetermined period of time, it may be caused by a port disabling problem, or it may be caused by a network failure or a device failure problem. Therefore, in this embodiment, in order to avoid that, after modifying the port mapping relationship, the response request cannot be sent through the modified port mapping relationship, resulting in invalid modification of the port mapping relationship, before modifying the mapping relationship, send a request to the client by sending a message to the client. The keep-alive command detects whether the network or the client is faulty, so as to eliminate other possible problems.

具体来说,保活命令发送的端口与连接请求发送的端口是不一样的,保活命令的端口是http端口,而连接请求的端口是RTSP端口,因此,不会出现端口禁用的问题。监控设备与客户端发送保活命令的具体过程包括:监控设备通过路由器向客户端发送保活命令,并开始计时;如果网络或者设备出现故障,这时客户端便不会接收到该保活命令,也就不会向监控设备发送保活响应命令,也即:监控设备在发送保活命令起的第二预定时长内,不会接收到保活响应命令,监控设备便知道未接收到客户端发送其他请求的原因,是因为网络或者设备出现故障,而非是端口被禁用。相反,如果网络正确并且未出现故障,这时客户端便可成功接收到该保活命令,并通过路由器向监控设备发送保活响应命令,监控设备接收到保活命令后,则知晓客户端与监控设备之间网络是正常的,这时可判定是因为端口禁用导致客户端不能接收到响应请求,则继续执行S205-S207。Specifically, the port for sending the keep-alive command is different from the port for sending the connection request. The port for the keep-alive command is the http port, and the port for the connection request is the RTSP port. Therefore, the problem of port disabling does not occur. The specific process of sending the keep-alive command between the monitoring device and the client includes: the monitoring device sends the keep-alive command to the client through the router, and starts timing; if the network or device fails, the client will not receive the keep-alive command. , it will not send a keep-alive response command to the monitoring device, that is, the monitoring device will not receive a keep-alive response command within the second predetermined period of time after sending the keep-alive command, and the monitoring device will know that it has not received the client Other requests were sent because of network or device failure, not because the port was disabled. On the contrary, if the network is correct and there is no fault, the client can successfully receive the keep-alive command, and send a keep-alive response command to the monitoring device through the router. After the monitoring device receives the keep-alive command, it knows that the client has If the network between the monitoring devices is normal, it can be determined that the client cannot receive the response request because the port is disabled, and then continue to execute S205-S207.

S205、向路由器发送映射关系取消指令,映射关系取消指令用于取消内部端口与外部端口的映射关系;S205, sending a mapping relationship cancellation instruction to the router, where the mapping relationship cancellation instruction is used to cancel the mapping relationship between the internal port and the external port;

S206、若接收到路由器发送的映射关系取消成功的提示信息,则向路由器发送映射关系创建指令,映射关系创建指令用于建立备用端口与外部端口的映射关系。S206. If receiving the prompt information sent by the router that the mapping relationship is cancelled successfully, send a mapping relationship creation instruction to the router, where the mapping relationship creation instruction is used to establish the mapping relationship between the standby port and the external port.

S207、若接收到路由器发送的映射关系建立成功的提示信息,则将响应请求通过备用端口发送至路由器,以使路由器通过外部端口将响应请求转发至客户端,从而建立监控设备与客户端的连接。S207, if receiving the prompt information sent by the router that the mapping relationship is established successfully, send the response request to the router through the standby port, so that the router forwards the response request to the client through the external port, thereby establishing the connection between the monitoring device and the client.

在本实施例中,通过备用端口替换内部端口时,监控设备需要与路由器进行交互,先向路由器发送映射关系取消指令,取消内部端口与外部端口的映射关系,若成功取消,则路由器会向监控设备发送映射关系取消成功的提示信息,这时监控设备会再向路由器发送映射关系创建指令,来建立备用端口与外部端口的映射关系,若成功建立,这时路由器会向监控设备发送映射关系建立成功的提示信息,只有映射关系成功取消并建立后,才会将该响应请求通过备用端口再次发送至路由器,从而保证映射关系的成功修改。In this embodiment, when the internal port is replaced by the spare port, the monitoring device needs to interact with the router, and first sends a mapping relationship cancellation instruction to the router to cancel the mapping relationship between the internal port and the external port. The device sends a message indicating that the mapping relationship is canceled successfully. At this time, the monitoring device will send a mapping relationship creation instruction to the router to establish the mapping relationship between the standby port and the external port. If the mapping relationship is established successfully, the router will send a mapping relationship to the monitoring device. For successful prompt information, only after the mapping relationship is successfully cancelled and established, the response request will be sent to the router again through the standby port, so as to ensure the successful modification of the mapping relationship.

下面通过一个具体的应用场景实例描述,来对本方案所述的监控设备建立连接的方法进行说明。在本实施例中,监控设备为NVR,客户端和NVR需要建立RTSP连接,客户端向NVR发送的连接请求为OPTIONS请求。并且,RTSP的标准端口(内部端口)为554,此处备用端口以555举例,RTSP的外部端口为8554,NVR的IP地址是192.168.1.100,路由器的WAN口地址为192.168.0.10。The following describes the method for establishing a connection for the monitoring device described in this solution by describing a specific application scenario example. In this embodiment, the monitoring device is an NVR, the client and the NVR need to establish an RTSP connection, and the connection request sent by the client to the NVR is an OPTIONS request. In addition, the standard port (internal port) of RTSP is 554, here the spare port is 555, the external port of RTSP is 8554, the IP address of NVR is 192.168.1.100, and the WAN port address of the router is 192.168.0.10.

参见图5,本发明实施例提供的整体方案流程图;通过该图可以看出,本方案主要分为如下几个步骤:Referring to FIG. 5, the overall solution flow chart provided by the embodiment of the present invention; it can be seen from this figure that the solution is mainly divided into the following steps:

第一步:NVR记录端口映射的外部端口号,客户端添加NVR;Step 1: The NVR records the external port number of the port mapping, and the client adds the NVR;

其中,该外部端口号即为外部端口的端口号,该步骤主要包括:监控设备发起UPNP(Universal Plug and Play,通用即插即用)并记录映射后的端口,客户端添加监控设备,监控设备向客户端发送携带外部端口的RTSP地址,例如:NVR接入到路由器下后,开启UPNP端口映射,把HTTP、RTSP等端口映射到NAT外,其中554端口映射为8554,然后客户端添加NVR,NVR上线并将实况回放的RTSP url返回给客户端,其中RTSP url的格式以实况主流举例:rtsp://192.168.0.10:8554/media/video1,192.168.0.10是路由器的WAN口地址,8554是NVR端口映射后的外部端口。The external port number is the port number of the external port, and the steps mainly include: the monitoring device initiates UPNP (Universal Plug and Play, Universal Plug and Play) and records the mapped port, the client adds the monitoring device, and the monitoring device Send the RTSP address carrying the external port to the client, for example: after the NVR is connected to the router, enable UPNP port mapping, map HTTP, RTSP and other ports to the outside of the NAT, where port 554 is mapped to 8554, and then the client adds the NVR, The NVR goes online and returns the RTSP url of the live playback to the client. The format of the RTSP url is based on the live mainstream example: rtsp://192.168.0.10:8554/media/video1, 192.168.0.10 is the WAN port address of the router, and 8554 is the WAN port address of the router. External port after NVR port mapping.

第二步:客户端发起RTSP实况请求,NVR检测到RTSP OPTIONS信令返回后无后续流程,发起保活命令,确认客户端是否在线。Step 2: The client initiates an RTSP live request, and the NVR detects that there is no follow-up process after the RTSP OPTIONS signaling is returned, and initiates a keep-alive command to confirm whether the client is online.

第三步:NVR取消RTSP端口554的端口映射,并以555端口映射到8854端口,NVR通过555端口继续完成RTSP信令交互和音视频流传输。Step 3: NVR cancels the port mapping of RTSP port 554, and maps port 555 to port 8854. NVR continues to complete RTSP signaling interaction and audio and video streaming through port 555.

需要说明的是,图5的整体流程图中未具体说明发起保活命令的过程,参见图6,为本发明实施例提供的穿NAT交互时序图,通过该时序图对上述的第三步和第四部进行说明,具体包括:It should be noted that the overall flow chart of FIG. 5 does not specifically describe the process of initiating a keep-alive command. Referring to FIG. 6 , it is a sequence diagram of the interaction through NAT provided by the embodiment of the present invention. The fourth part is explained, including:

F1:客户端向监控设备(NVR)的RTSP外部映射端口建立RTSP连接,发送OPTIONS请求。F1: The client establishes an RTSP connection to the RTSP external mapping port of the monitoring device (NVR) and sends an OPTIONS request.

F2:路由器转发OPTIONS给NVR。F2: The router forwards OPTIONS to the NVR.

F3:NVR响应OPTIONS请求,返回响应请求。F3: The NVR responds to the OPTIONS request and returns the response request.

F4:路由器禁用554端口,因此不对F3中的返回报文做转发,此时NVR通过HTTP端口发起保活。F4: The router disables port 554, so it does not forward the returned packets in F3. At this time, the NVR initiates keep-alive through the HTTP port.

F5:路由器转发保活命令给客户端。F5: The router forwards the keep-alive command to the client.

F6:客户端响应保活命令。F6: The client responds to the keep alive command.

F7:路由器转发保活命令给NVR。F7: The router forwards the keep-alive command to the NVR.

F8:NVR取消RTSP 554端口的端口映射。F8: NVR cancels port mapping of RTSP 554 port.

F9:路由器返回取消端口映射成功。F9: The router returns that the port mapping was cancelled successfully.

F10:NVR把555端口映射到之前554端口的外部映射端口。F10: NVR maps port 555 to the external mapped port of port 554.

F11:路由器返回端口映射成功。F11: The router returns that the port mapping is successful.

F12:NVR通过555端口将继续返回响应请求,并在555端口完成后续的RTSP建流及音视频流传输。F12: The NVR will continue to return the response request through port 555, and complete the subsequent RTSP stream construction and audio and video stream transmission on port 555.

F13:路由器进行报文转发。F13: The router forwards the packet.

综上可以看出,在本申请中,可通过客户端与监控主设备之间的http保活命令和RTSP信令的交互,建立一种自动修改端口映射的机制,可以解决在NAT内的监控设备,被路由器禁用554端口的问题,以解决NAT内的监控设备无法实况、回放问题。From the above, it can be seen that in this application, a mechanism for automatically modifying port mapping can be established through the interaction of the http keep-alive command and RTSP signaling between the client and the monitoring master device, which can solve the monitoring in the NAT The problem that the 554 port is disabled by the router to solve the problem that the monitoring equipment in the NAT cannot live and playback.

下面对本发明实施例提供的监控设备建立连接的装置进行介绍,下文描述的监控设备建立连接的装置与上文描述的监控设备建立连接的方法可以相互参照。The following describes an apparatus for establishing a connection for a monitoring device provided by an embodiment of the present invention. The apparatus for establishing a connection for a monitoring device described below and the method for establishing a connection for a monitoring device described above may refer to each other.

参见图7,本发明实施例提供的一种监控设备建立连接的装置结构示意图;该装置包括:Referring to FIG. 7 , a schematic structural diagram of an apparatus for establishing a connection between monitoring equipment provided by an embodiment of the present invention; the apparatus includes:

接收模块21,用于通过内部端口接收路由器转发的连接请求,所述连接请求为客户端通过外部端口发送至所述路由器,所述内部端口与所述外部端口具有映射关系;A receiving module 21, configured to receive a connection request forwarded by a router through an internal port, where the connection request is sent by a client to the router through an external port, and the internal port has a mapping relationship with the external port;

第一发送模块22,用于将与所述连接请求对应的响应请求通过所述内部端口发送至所述路由器,以使所述路由器通过所述外部端口将所述响应请求转发至所述客户端;a first sending module 22, configured to send a response request corresponding to the connection request to the router through the internal port, so that the router forwards the response request to the client through the external port ;

端口替换模块23,用于在发送完所述响应请求的第一预定时长内,未接收所述客户端发送的其他请求时,在所述路由器取消所述内部端口与所述外部端口的映射关系,并建立所述备用端口与所述外部端口的映射关系;The port replacement module 23 is configured to cancel the mapping relationship between the internal port and the external port when the router does not receive other requests sent by the client within the first predetermined period of time after the response request is sent , and establish the mapping relationship between the standby port and the external port;

第二发送模块24,用于将所述响应请求通过所述备用端口发送至所述路由器,以使所述路由器通过所述外部端口将所述响应请求转发至所述客户端,从而建立所述监控设备与所述客户端的连接。The second sending module 24 is configured to send the response request to the router through the standby port, so that the router forwards the response request to the client through the external port, thereby establishing the The connection between the monitoring device and the client is monitored.

其中,所述接收模块具体用于:通过内部端口接收路由器转发的建立RTSP连接的OPTIONS请求。The receiving module is specifically configured to: receive an OPTIONS request for establishing an RTSP connection forwarded by a router through an internal port.

其中,所述端口替换模块包括:Wherein, the port replacement module includes:

第一指令发送模块,用于向所述路由器发送映射关系取消指令,所述映射关系取消指令用于取消所述内部端口与所述外部端口的映射关系;a first instruction sending module, configured to send a mapping relationship cancellation instruction to the router, where the mapping relationship cancellation instruction is used to cancel the mapping relationship between the internal port and the external port;

第二指令发送模块,用于在接收到所述路由器发送的映射关系取消成功的提示信息时,向所述路由器发送映射关系创建指令,所述映射关系创建指令用于建立所述备用端口与所述外部端口的映射关系。The second instruction sending module is configured to send a mapping relationship creation instruction to the router when receiving the prompt information sent by the router that the mapping relationship is canceled successfully, where the mapping relationship creation instruction is used to establish the connection between the standby port and the Describe the mapping relationship of external ports.

其中,所述第二发送模块具体用于:在接收到所述路由器发送的映射关系建立成功的提示信息时,将所述响应请求通过所述备用端口发送至所述路由器。Wherein, the second sending module is specifically configured to: send the response request to the router through the standby port when receiving the prompt information sent by the router that the mapping relationship is established successfully.

其中,本方案还包括:Among them, this program also includes:

第三发送模块,用于通过所述路由器向所述客户端发送保活命令;a third sending module, configured to send a keep-alive command to the client through the router;

判断模块,用于判断第二预定时长内,是否接收到所述客户端通过所述路由器转发的保活响应命令;a judging module for judging whether a keep-alive response command forwarded by the client through the router is received within a second predetermined period of time;

所述端口替换模块,用于在第二预定时长内接收到所述客户端通过所述路由器转发的保活响应命令时,在所述路由器取消所述内部端口与所述外部端口的映射关系,并建立所述备用端口与所述外部端口的映射关系。The port replacement module is configured to cancel the mapping relationship between the internal port and the external port when the router cancels the mapping relationship between the internal port and the external port when receiving the keep-alive response command forwarded by the client through the router within a second predetermined period of time, and establishing a mapping relationship between the standby port and the external port.

参见图8,本发明实施例提供的一种电子设备结构示意图,该设备包括:Referring to FIG. 8 , a schematic structural diagram of an electronic device provided by an embodiment of the present invention includes:

存储器31,用于存储计算机程序;memory 31 for storing computer programs;

处理器32,用于执行所述计算机程序时实现如上述任意方法实施例所述的监控设备建立连接的方法的步骤。The processor 32 is configured to implement the steps of the method for establishing a connection for a monitoring device according to any of the above method embodiments when executing the computer program.

在本实施例中,设备可以是NVR或者IPC等设备。In this embodiment, the device may be a device such as an NVR or an IPC.

该设备可以包括存储器31、处理器32和总线33。The device may include a memory 31 , a processor 32 and a bus 33 .

其中,存储器31至少包括一种类型的可读存储介质,所述可读存储介质包括闪存、硬盘、多媒体卡、卡型存储器(例如,SD或DX存储器等)、磁性存储器、磁盘、光盘等。存储器31在一些实施例中可以是设备的内部存储单元,例如该设备的硬盘。存储器31在另一些实施例中也可以是设备的外部存储设备,例如设备上配备的插接式硬盘,智能存储卡(SmartMedia Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)等。进一步地,存储器31还可以既包括设备的内部存储单元也包括外部存储设备。存储器31不仅可以用于存储安装于设备的应用软件及各类数据。The memory 31 includes at least one type of readable storage medium, including flash memory, hard disk, multimedia card, card-type memory (eg, SD or DX memory, etc.), magnetic memory, magnetic disk, optical disk, and the like. The memory 31 may in some embodiments be an internal storage unit of the device, such as a hard disk of the device. In other embodiments, the memory 31 may also be an external storage device of the device, such as a plug-in hard disk, a smart memory card (SmartMedia Card, SMC), a secure digital (Secure Digital, SD) card, a flash memory card ( Flash Card), etc. Further, the memory 31 may also include both an internal storage unit of the device and an external storage device. The memory 31 can be used not only for storing application software and various types of data installed in the device.

处理器32在一些实施例中可以是一中央处理器(Central Processing Unit,CPU)、控制器、微控制器、微处理器或其他数据处理芯片,用于运行存储器31中存储的程序代码或处理数据。In some embodiments, the processor 32 may be a central processing unit (Central Processing Unit, CPU), controller, microcontroller, microprocessor or other data processing chip for executing program codes or processing stored in the memory 31 data.

该总线33可以是外设部件互连标准(peripheral component interconnect,简称PCI)总线或扩展工业标准结构(extended industry standard architecture,简称EISA)总线等。该总线可以分为地址总线、数据总线、控制总线等。为便于表示,图8中仅用一条粗线表示,但并不表示仅有一根总线或一种类型的总线。The bus 33 may be a peripheral component interconnect (PCI for short) bus or an extended industry standard architecture (extended industry standard architecture, EISA for short) bus or the like. The bus can be divided into address bus, data bus, control bus and so on. For ease of presentation, only one thick line is used in FIG. 8, but it does not mean that there is only one bus or one type of bus.

进一步地,设备还可以包括网络接口34,网络接口34可选的可以包括有线接口和/或无线接口(如WI-FI接口、蓝牙接口等),通常用于在该设备与其他电子设备之间建立通信连接。Further, the device may also include a network interface 34, and the network interface 34 may optionally include a wired interface and/or a wireless interface (such as a WI-FI interface, a Bluetooth interface, etc.), which is usually used between the device and other electronic devices Establish a communication connection.

图8仅示出了具有组件31-34的设备,本领域技术人员可以理解的是,图8示出的结构并不构成对设备的限定,可以包括比图示更少或者更多的部件,或者组合某些部件,或者不同的部件布置。FIG. 8 only shows the device with components 31-34. Those skilled in the art can understand that the structure shown in FIG. Either some components are combined, or different component arrangements.

本发明实施例还提供了一种计算机可读存储介质,所述计算机可读存储介质上存储有计算机程序,所述计算机程序被处理器执行时实现如上述任意方法实施例所述的监控设备建立连接的方法的步骤。Embodiments of the present invention further provide a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the monitoring device establishment according to any of the foregoing method embodiments is implemented. The steps of the method of connection.

其中,该存储介质可以包括:U盘、移动硬盘、只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。Wherein, the storage medium may include: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk and other various storage media that can store program codes medium.

本说明书中各个实施例采用递进的方式描述,每个实施例重点说明的都是与其他实施例的不同之处,各个实施例之间相同相似部分互相参见即可。The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same and similar parts between the various embodiments can be referred to each other.

对所公开的实施例的上述说明,使本领域专业技术人员能够实现或使用本发明。对这些实施例的多种修改对本领域的专业技术人员来说将是显而易见的,本文中所定义的一般原理可以在不脱离本发明的精神或范围的情况下,在其它实施例中实现。因此,本发明将不会被限制于本文所示的这些实施例,而是要符合与本文所公开的原理和新颖特点相一致的最宽的范围。The above description of the disclosed embodiments enables any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (10)

1. A method for a monitoring device to establish a connection, comprising:
receiving a connection request forwarded by a router through an internal port, wherein the connection request is sent to the router through an external port by a client, and the internal port and the external port have a mapping relation;
sending a response request corresponding to the connection request to the router through the internal port, so that the router forwards the response request to the client through the external port;
if other requests sent by the client are not received within a first preset time length after the response request is sent, canceling the mapping relation between the internal port and the external port at the router, and establishing the mapping relation between a standby port and the external port;
and sending the response request to the router through the standby port, so that the router forwards the response request to the client through the external port, and the monitoring device is connected with the client.
2. The method of claim 1, wherein receiving the connection request forwarded by the router through the internal port comprises:
and receiving an OPTIONS request for establishing RTSP connection forwarded by the router through the internal port.
3. The method of claim 1, wherein canceling the mapping between the internal port and the external port and establishing the mapping between the standby port and the external port at the router comprises:
sending a mapping relation canceling instruction to the router, wherein the mapping relation canceling instruction is used for canceling the mapping relation between the internal port and the external port;
and if receiving prompt information that the mapping relation cancellation sent by the router is successful, sending a mapping relation establishing instruction to the router, wherein the mapping relation establishing instruction is used for establishing the mapping relation between the standby port and the external port.
4. The method of claim 3, wherein sending the response request to the router through the backup port comprises:
and if receiving prompt information that the mapping relation is successfully established and sent by the router, sending the response request to the router through the standby port.
5. The method according to any one of claims 1 to 4, wherein if no other request sent by the client is received within a first predetermined time period after sending the response request, the method further comprises:
sending a keep-alive command to the client through the router;
judging whether a keep-alive response command forwarded by the client through the router is received within a second preset time length;
if yes, the step of canceling the mapping relation between the internal port and the external port and establishing the mapping relation between the standby port and the external port in the router is executed.
6. An apparatus for monitoring device connection establishment, comprising:
the system comprises a receiving module, a sending module and a receiving module, wherein the receiving module is used for receiving a connection request forwarded by a router through an internal port, the connection request is sent to the router through an external port by a client, and the internal port and the external port have a mapping relation;
a first sending module, configured to send a response request corresponding to the connection request to the router through the internal port, so that the router forwards the response request to the client through the external port;
a port replacement module, configured to cancel, at the router, a mapping relationship between the internal port and the external port and establish a mapping relationship between a standby port and the external port when the response request is sent within a first predetermined time period after the response request is sent and other requests sent by the client are not received;
and the second sending module is used for sending the response request to the router through the standby port so that the router forwards the response request to the client through the external port, and thus the connection between the monitoring device and the client is established.
7. The apparatus of claim 6, further comprising:
a third sending module, configured to send a keep-alive command to the client through the router;
the judging module is used for judging whether a keep-alive response command forwarded by the client through the router is received within a second preset time length;
the port replacement module is configured to cancel, at the router, the mapping relationship between the internal port and the external port and establish the mapping relationship between the standby port and the external port when a keep-alive response command forwarded by the client through the router is received within a second predetermined time period.
8. An electronic device, comprising:
a memory for storing a computer program;
a processor for implementing the steps of the method of establishing a connection by a monitoring device according to any of claims 1 to 5 when executing the computer program.
9. A connection establishment system, comprising: client, router, and electronic device according to claim 8.
10. A computer-readable storage medium, characterized in that a computer program is stored on the computer-readable storage medium, which computer program, when being executed by a processor, carries out the steps of the method for a monitoring device to establish a connection according to one of claims 1 to 5.
CN202010186648.8A 2020-03-17 2020-03-17 Method, device, equipment, system and storage medium for establishing connection of monitoring equipment Active CN113411367B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010186648.8A CN113411367B (en) 2020-03-17 2020-03-17 Method, device, equipment, system and storage medium for establishing connection of monitoring equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010186648.8A CN113411367B (en) 2020-03-17 2020-03-17 Method, device, equipment, system and storage medium for establishing connection of monitoring equipment

Publications (2)

Publication Number Publication Date
CN113411367A CN113411367A (en) 2021-09-17
CN113411367B true CN113411367B (en) 2022-07-19

Family

ID=77677148

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010186648.8A Active CN113411367B (en) 2020-03-17 2020-03-17 Method, device, equipment, system and storage medium for establishing connection of monitoring equipment

Country Status (1)

Country Link
CN (1) CN113411367B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116455860A (en) * 2022-01-07 2023-07-18 腾讯科技(深圳)有限公司 Communication message processing method, device, equipment and storage medium

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104363143A (en) * 2014-11-27 2015-02-18 上海斐讯数据通信技术有限公司 Port mapping test method of wireless router
CN108540590A (en) * 2018-03-28 2018-09-14 深圳市网心科技有限公司 UPnP network port mapping method, electronic equipment, network system and storage medium

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7676579B2 (en) * 2002-05-13 2010-03-09 Sony Computer Entertainment America Inc. Peer to peer network communication
US10505757B2 (en) * 2014-12-12 2019-12-10 Nxp Usa, Inc. Network interface module and a method of changing network configuration parameters within a network device

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104363143A (en) * 2014-11-27 2015-02-18 上海斐讯数据通信技术有限公司 Port mapping test method of wireless router
CN108540590A (en) * 2018-03-28 2018-09-14 深圳市网心科技有限公司 UPnP network port mapping method, electronic equipment, network system and storage medium

Also Published As

Publication number Publication date
CN113411367A (en) 2021-09-17

Similar Documents

Publication Publication Date Title
US20150304364A1 (en) Method, System, and Terminal for Web Real-Time Communication
CN111246152B (en) Video conference automatic recovery method and device, storage medium and electronic device
US10034057B2 (en) Message processing method, device, gateway, STB and IPTV
US10069605B1 (en) System and method for the detection and remediation of non-responsive customer premises equipment
CN112398689B (en) Network recovery method and device, storage medium and electronic equipment
CN103518205B (en) Method and automation equipment for restricting operation authority
CN113055225A (en) Method for acquiring network fault analysis data, terminal and server
CN105429799A (en) Server backup method and device
CN113572669B (en) Scene processing method, device, intelligent gateway and processor
CN114745413A (en) Access control method, device, computer equipment and storage medium for server
CN110809262A (en) Internet of things equipment operation and maintenance management method based on COAP protocol
CN113411367B (en) Method, device, equipment, system and storage medium for establishing connection of monitoring equipment
CN107864058A (en) Fault judgment method and device
CN114143905B (en) Session establishing method, communication system, electronic device and storage medium
CN113949631B (en) Client disaster recovery processing method, system and electronic equipment
CN115150647A (en) A system and method for sharing media resources for network-based communications
CN106330513A (en) Method and device for processing tr069 protocol information
CN105634810B (en) Method and system for accessing universal plug and play device, access device
CN112463174B (en) Method, device, equipment and storage medium for remotely unloading server
JP5535757B2 (en) Client device and program
CN108551429A (en) Flow control method of application program, electronic device and computer readable storage medium
CN113411228A (en) Network condition determining method and server
CN114650283A (en) Method and device for dynamically switching cloud storage service, electronic equipment and storage medium
CN115499617B (en) Device control method, device, electronic device and readable storage medium
CN105338398A (en) Set top box management method, device and system

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