CN116366619A - Data transmission method, device, equipment and storage medium - Google Patents

Data transmission method, device, equipment and storage medium Download PDF

Info

Publication number
CN116366619A
CN116366619A CN202111624373.2A CN202111624373A CN116366619A CN 116366619 A CN116366619 A CN 116366619A CN 202111624373 A CN202111624373 A CN 202111624373A CN 116366619 A CN116366619 A CN 116366619A
Authority
CN
China
Prior art keywords
data
data transmission
terminal equipment
communication connection
communication
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.)
Pending
Application number
CN202111624373.2A
Other languages
Chinese (zh)
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.)
Beijing Qihoo Technology Co Ltd
Original Assignee
Beijing Qihoo Technology 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 Beijing Qihoo Technology Co Ltd filed Critical Beijing Qihoo Technology Co Ltd
Priority to CN202111624373.2A priority Critical patent/CN116366619A/en
Publication of CN116366619A publication Critical patent/CN116366619A/en
Pending legal-status Critical Current

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/01Protocols
    • H04L67/02Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
    • 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

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer And Data Communications (AREA)

Abstract

The invention discloses a data transmission method, a device, equipment and a storage medium, belonging to the technical field of data processing, wherein the method comprises the following steps: when a communication request sent by a terminal device is received, a communication line between the terminal device and the communication request is established according to the communication request; when a handshake request sent by the terminal equipment through the communication line is received, establishing communication connection with the terminal equipment according to the handshake request; and sending the data related to the front-end browser to the terminal equipment through the communication connection. Compared with the existing polling mode, the server and the terminal equipment in the scheme can establish the durable communication connection only by completing one-time handshake, and then both sides can send data, so that the real-time performance of data transmission is reflected, the waste of server connection resources can be avoided, and the data transmission effect is improved.

Description

Data transmission method, device, equipment and storage medium
Technical Field
The present invention relates to the field of data processing technologies, and in particular, to a data transmission method, apparatus, device, and storage medium.
Background
When the server and the front-end browser carry out live broadcast data transmission, the push of real-time data is needed, most of the previous technologies adopt polling, wherein the polling is that the browser sends http requests to the server at intervals, then the server returns the latest data to the client, the method is divided into short polling and long polling, the short polling refers to repeated http requests, and the defect that whether a target event is completed is queried is overcome, and the method comprises the following steps: wasting bandwidth and server resources, long polling refers to waiting for a target event to occur (keeping the current connection waiting for data to arrive or an appropriate timeout) while the server hold holds the http request, returning an http response.
It can be seen that the two polls have in common: each time a request needs to be initiated, it is possible to obtain results, which have some passivity. Therefore, the conventional data transmission method has a problem of wasting server connection resources.
The foregoing is provided merely for the purpose of facilitating understanding of the technical solutions of the present invention and is not intended to represent an admission that the foregoing is prior art.
Disclosure of Invention
The invention mainly aims to provide a data transmission method, a device, equipment and a storage medium, which aim to solve the technical problem of how to avoid wasting server connection resources.
To achieve the above object, the present invention provides a data transmission method, including:
when a communication request sent by a terminal device is received, a communication line between the terminal device and the communication request is established according to the communication request;
when a handshake request sent by the terminal equipment through the communication line is received, establishing communication connection with the terminal equipment according to the handshake request;
and sending the data related to the front-end browser to the terminal equipment through the communication connection.
Optionally, the sending the data related to the front-end browser to the terminal device through the communication connection includes:
detecting whether data exists in a target channel, wherein the target channel is used for storing data related to a front-end browser;
when data exists in the target channel, acquiring target data in the target channel;
and sending the target data to the terminal equipment through the communication connection so that the terminal equipment displays the target data on a front-end browser.
Optionally, the detecting whether the data exists in the target channel includes:
acquiring target channel information corresponding to a target channel;
Determining a data storage state corresponding to the target channel according to the target channel information;
and detecting whether data exists in the target channel according to the data storage state.
Optionally, before the data related to the front-end browser is sent to the terminal device through the communication connection, the method further includes:
performing timing task cooperative operation to detect whether data exists in the second channel;
when data exists in the second channel, acquiring the current time;
when the current time accords with a first preset time condition, acquiring first browser data related to a front-end browser from a first preset database;
and storing the first browser data into a target channel.
Optionally, after the current time is obtained, the method further includes:
when the current time accords with a second preset time condition, second browser data related to the front-end browser are acquired from a second preset database;
and storing the second browser data into a target channel.
Optionally, after the current time is obtained, the method further includes:
and closing the communication connection when the current time accords with a third preset time condition.
Optionally, after the current time is obtained, the method further includes:
acquiring the last data generation time;
calculating interval time according to the current time and the last data generation time;
and when the interval time exceeds the preset time, judging that the current time accords with a third preset time condition.
Optionally, after calculating the interval time according to the current time and the last data generation time, the method further includes:
when the interval time does not exceed the preset time, detecting whether the current time is a multiple of a first preset value;
and when the current time is a multiple of the first preset value, judging that the current time accords with a first preset time condition.
Optionally, after calculating the interval time according to the current time and the last data generation time, the method further includes:
detecting whether the current time is a multiple of a second preset value when the interval time does not exceed the preset time;
and when the current time is a multiple of the second preset value, judging that the current time meets a second preset time condition.
Optionally, before the data related to the front-end browser is sent to the terminal device through the communication connection, the method further includes:
Performing read-co-procedure operation to detect whether the terminal equipment sends request information;
if the terminal equipment sends the request information, the request information sent by the terminal equipment is read;
and storing the request information sent by the terminal equipment into a first channel.
Optionally, after performing the read cooperative operation to detect whether the terminal device sends the request information, the method further includes:
and if the terminal equipment does not send the request information, continuously waiting for the request information of the terminal equipment.
Optionally, before the data related to the front-end browser is sent to the terminal device through the communication connection, the method further includes:
performing write cooperative operation to detect whether data exists in a first channel, wherein the first channel is used for storing request information sent by terminal equipment;
acquiring first data in the first channel when the data exists in the first channel;
detecting a data type of the first data;
and when the data type is a first preset type, storing the first data into a second channel.
Optionally, after detecting the data type of the first data, the method further includes:
And when the data type is a second preset type, performing heartbeat detection according to the first data.
Optionally, after detecting the data type of the first data, the method further includes:
and closing the communication connection when the data type is a third preset type.
In addition, in order to achieve the above object, the present invention also proposes a data transmission device including:
the communication line module is used for establishing a communication line with the terminal equipment according to the communication request when the communication request sent by the terminal equipment is received;
the communication connection module is used for establishing communication connection with the terminal equipment according to the handshake request when the handshake request sent by the terminal equipment through the communication line is received;
and the data transmitting module is used for transmitting the data related to the front-end browser to the terminal equipment through the communication connection.
Optionally, the data sending module is further configured to detect whether data exists in a target channel, where the target channel is used to store data related to a front-end browser; when data exists in the target channel, acquiring target data in the target channel; and sending the target data to the terminal equipment through the communication connection so that the terminal equipment displays the target data on a front-end browser.
Optionally, the data sending module is further configured to obtain target channel information corresponding to a target channel; determining a data storage state corresponding to the target channel according to the target channel information; and detecting whether data exists in the target channel according to the data storage state.
Optionally, the data transmission device further includes:
the timing task module is used for carrying out timing task cooperative operation so as to detect whether data exist in the second channel; when data exists in the second channel, acquiring the current time; when the current time accords with a first preset time condition, acquiring first browser data related to a front-end browser from a first preset database; and storing the first browser data into a target channel.
In addition, in order to achieve the above object, the present invention also proposes a data transmission apparatus including: the data transmission system comprises a memory, a processor and a data transmission program stored in the memory and capable of running on the processor, wherein the data transmission program realizes the data transmission method when being executed by the processor.
In addition, in order to achieve the above object, the present invention also proposes a storage medium having stored thereon a data transmission program which, when executed by a processor, implements the data transmission method as described above.
In the data transmission method provided by the invention, when a communication request sent by a terminal device is received, a communication line between the terminal device and the communication request is established according to the communication request; when a handshake request sent by the terminal equipment through the communication line is received, establishing communication connection with the terminal equipment according to the handshake request; and sending the data related to the front-end browser to the terminal equipment through the communication connection. Compared with the existing polling mode, the server and the terminal equipment in the scheme can establish the durable communication connection only by completing one-time handshake, and then both sides can send data, so that the real-time performance of data transmission is reflected, the waste of server connection resources can be avoided, and the data transmission effect is improved.
Drawings
FIG. 1 is a schematic diagram of a data transmission device in a hardware operating environment according to an embodiment of the present invention;
fig. 2 is a flow chart of a first embodiment of the data transmission method of the present invention;
fig. 3 is a flow chart of a second embodiment of the data transmission method of the present invention;
fig. 4 is a schematic overall flow chart of data transmission according to an embodiment of the data transmission method of the present invention;
Fig. 5 is a flowchart of a third embodiment of a data transmission method according to the present invention;
fig. 6 is a schematic functional block diagram of a first embodiment of the data transmission device of the present invention.
The achievement of the objects, functional features and advantages of the present invention will be further described with reference to the accompanying drawings, in conjunction with the embodiments.
Detailed Description
It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the invention.
Referring to fig. 1, fig. 1 is a schematic diagram of a data transmission device structure of a hardware operating environment according to an embodiment of the present invention.
As shown in fig. 1, the data transmission apparatus may include: a processor 1001, such as a central processing unit (Central Processing Unit, CPU), a communication bus 1002, a user interface 1003, a network interface 1004, a memory 1005. Wherein the communication bus 1002 is used to enable connected communication between these components. The user interface 1003 may include a Display, an input unit such as keys, and the optional user interface 1003 may also include a standard wired interface, a wireless interface. The network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., wi-Fi interface). The memory 1005 may be a high-speed random access memory (Random Access Memory, RAM) or a stable memory (non-volatile memory), such as a disk memory. The memory 1005 may also optionally be a storage device separate from the processor 1001 described above.
It will be appreciated by those skilled in the art that the device structure shown in fig. 1 does not constitute a limitation of the data transmission device and may include more or fewer components than shown, or may combine certain components, or a different arrangement of components.
As shown in fig. 1, an operating system, a network communication module, a user interface module, and a data transmission program may be included in the memory 1005 as one type of storage medium.
In the data transmission device shown in fig. 1, the network interface 1004 is mainly used for connecting to an external network and performing data communication with other network devices; the user interface 1003 is mainly used for connecting user equipment and communicating data with the user equipment; the apparatus of the present invention calls a data transmission program stored in the memory 1005 through the processor 1001 and executes the data transmission method provided by the embodiment of the present invention.
Based on the above hardware structure, the embodiment of the data transmission method of the invention is provided.
Referring to fig. 2, fig. 2 is a flowchart of a first embodiment of a data transmission method according to the present invention.
In a first embodiment, the data transmission method includes:
and step S10, when a communication request sent by the terminal equipment is received, a communication line between the terminal equipment and the terminal equipment is established according to the communication request.
It should be noted that, the execution body of the present embodiment may be a data transmission device, and the data transmission device may be a server device having a data processing function, or may be other devices that may implement the same or similar functions, which is not limited in this embodiment, and in this embodiment, a server device is described as an example.
It should be noted that the scheme can be applied to a server and used for data transmission between the server and terminal equipment corresponding to a front-end browser. The present embodiment is applicable to various scenes, for example, the present embodiment may be applied to various scenes such as a live broadcast data transmission scene, an image data transmission scene, and a web page data transmission scene, and may also be applied to other types of scenes, which are not limited in this embodiment, and in this embodiment, a live broadcast data transmission scene is taken as an example for explanation.
It should be understood that in a live data transmission scenario, a user may use a front-end browser to perform live viewing, so the front-end browser needs to acquire live data from a server in real time according to live information selected by the user, and then parse the live data to display live video to the user.
It can be understood that, for data transmission in the above scenario, most of the prior art adopts a polling mode, and the browser sends http requests to the server at intervals, and then the server returns the latest data to the client. Whether long polling or short polling, the browser needs to initiate a request each time to acquire a result, the result has certain passivity, and the server cannot actively send data to the browser. Therefore, the data transmission by the polling method wastes the server connection resources and may affect the server performance and the live broadcast effect, i.e. the existing data transmission method cannot achieve a better data transmission effect in the scene.
It should be noted that, based on the above-mentioned problem, the data transmission is not carried out by adopting a polling mode, but by adopting a new mode, based on the mode, the browser and the server can establish persistent connection only by completing handshake once, and then both sides can send data, which fully solves the problem that the server cannot actively push data to the browser, and reflects the real-time performance of data transmission. In addition, the connection closing time can be controlled by the method, and the connection can be automatically closed as long as a certain party of the server or the client actively closes the connection. In addition, the mode has a reconnection mechanism, and reconnection can be automatically performed when connection is not enabled and is not in a closed state, so that the two parties can be ensured to successfully send data as far as possible.
It will be appreciated that based on the above-described concept, in order to establish a connection between the server and the terminal device where the front-end browser is located in this way, the server may continually monitor for a communication request, upon receipt of a communication request sent by the terminal device, establish a communication line with the terminal device in accordance with the communication request.
It is understood that a communication line can be understood as a temporary communication connection between a server and a terminal device. In order to ensure information security and achieve better data transmission effect, the server in the scheme does not directly establish communication connection with the terminal equipment for data transmission after receiving the communication request, but establishes a communication line with the terminal equipment only according to the communication request, then carries out handshake through the communication line once, establishes communication connection between the server and the terminal equipment after handshake success, and can realize two-way communication between the server and the terminal equipment through the communication connection.
Step S20, when a handshake request sent by the terminal device through the communication line is received, a communication connection with the terminal device is established according to the handshake request.
It should be understood that after the terminal device and the server establish a communication line, the terminal device may send a handshake request, and the server may feedback a handshake response according to the handshake request after receiving the handshake request sent by the terminal device through the communication line, thereby completing a handshake operation between the terminal device and the server to establish a communication connection between the server and the terminal device.
It can be appreciated that after the communication connection between the server and the terminal device is established in the above manner, the subsequent data exchange can be directly realized based on the communication connection, so that the communication request is not required to be retransmitted, and the bandwidth resource is saved. The communication connection is a bi-directional communication connection, and the server and/or the terminal device may transmit data through the communication connection or receive data through the communication connection, which is not limited in this embodiment.
And step S30, data related to the front-end browser is sent to the terminal equipment through the communication connection.
It should be appreciated that in the case where the above communication connection exists between the server and the terminal device, if the data associated with the front-end browser is generated in the server, the server may directly send the data associated with the front-end browser to the terminal device through the communication connection, so that the terminal device displays the data on the front-end browser. Compared with the existing polling mode, the communication connection in the scheme has a bidirectional communication function, data can be flexibly sent to the terminal equipment through the communication connection according to actual conditions without sending the data to the terminal equipment under the condition of receiving the request of the terminal equipment, so that the waste of server connection resources is avoided, and a better data transmission effect can be achieved.
In a specific implementation, for example, in a live broadcast data transmission scene, a user watches live broadcast through a front-end browser, when the user accesses a live broadcast room is detected, communication connection between a server and terminal equipment can be established through the mode, then the server can directly transmit live broadcast data related to the live broadcast to the terminal equipment through the communication connection according to actual conditions, the terminal equipment can display live broadcast content to the user according to the received live broadcast data, so that the front end can display data in real time after the back-end data are generated, and the consumption condition of server resources is small.
It should be understood that, in addition to the above effect, the communication connection in the present solution can also be flexibly closed, that is, the communication connection may be closed by a server or a terminal device, and the closing time of the connection may be controlled, so long as the server or a party of the terminal device actively closes the connection, the connection may be automatically closed. In addition, the mode has a reconnection mechanism, and when the connection is not enabled and the communication connection is not actively closed by the server or the terminal equipment, reconnection can be automatically carried out, so that the two parties can be ensured to send data as far as possible, and the condition of data transmission failure is avoided.
In this embodiment, when a communication request sent by a terminal device is received, a communication line between the terminal device and the terminal device is established according to the communication request; when a handshake request sent by the terminal equipment through the communication line is received, establishing communication connection with the terminal equipment according to the handshake request; and sending the data related to the front-end browser to the terminal equipment through the communication connection. Compared with the existing polling mode, the server and the terminal equipment in the scheme can establish the durable communication connection only by completing one-time handshake, and then both sides can send data, so that the real-time performance of data transmission is reflected, the waste of server connection resources can be avoided, and the data transmission effect is improved.
In an embodiment, as shown in fig. 3, a second embodiment of the data transmission method according to the present invention is proposed based on the first embodiment, and the step S30 includes:
in step S301, it is detected whether there is data in a target channel, where the target channel is used to store data related to a front-end browser.
It should be noted that, in the present solution, the data transmission may be implemented by using a coroutine mechanism of the GO language, and fig. 4 may be referred to as a whole flow chart of data transmission in fig. 4. After the communication connection between the server and the terminal device is established, the data transmission flow of the scheme can be divided into four major parts, which are respectively: read coroutine, write coroutine, timed task coroutine, and output coroutine.
Note that a coroutine is a existence that is lighter than a thread, just as a process can own multiple threads, a thread can own multiple coroutines. Thus, a process may be composed of multiple threads, while a thread may be composed of multiple threads, as this embodiment is not limiting.
It should be understood that the reading protocol in this scheme is responsible for reading the request of the terminal device, and the output protocol is responsible for pushing data to the terminal device. The write-assisted procedure and the timing task-assisted procedure are both specifically responsible for processing the data logic, the write-assisted procedure is responsible for processing the scenario requested by the terminal device, and the timing task-assisted procedure is responsible for processing the scenario actively pushed by the server, which is not limited in this embodiment.
It should be noted that, in this embodiment, the three channels (channels) are a first channel (channel-1), a second channel (channel-2), and a target channel (channel-3), where the target channel may be a channel for storing data related to a front end browser to be sent, the first channel may be a channel for storing request information sent by a terminal device, and the second channel may be a channel for storing request data.
It should be appreciated that the server may perform an output pass operation to detect whether data is present in the target channel, send the data to the terminal device when data is present in the target channel, and continue to wait for data to be acquired when data is not present in the target channel.
Further, in order to more accurately detect whether data exists in the target channel, transmission efficiency is improved, target channel information corresponding to the target channel can be obtained, a data storage state corresponding to the target channel is determined according to the target channel information, and whether data exists in the target channel is detected according to the data storage state corresponding to the target channel.
Step S302, when data exists in the target channel, acquiring target data in the target channel.
It will be appreciated that in the case where there is data in the target channels, it is stated that these data need to be transmitted to the terminal device, and therefore, in this case, the data in the target channels can be acquired and referred to as target data.
And step S303, the target data is sent to the terminal equipment through the communication connection, so that the terminal equipment displays the target data on a front-end browser.
It should be appreciated that after data is present in the target channel and the target data is obtained from the target channel, the server may send the target data to the terminal device over the communication connection. After receiving the target data, the terminal device can display the target data on the front-end browser.
In a specific implementation, when live broadcast data exists in the target channel, the server may acquire the target live broadcast data from the target channel, and send the target live broadcast data to the terminal device through the communication connection. After receiving the target live broadcast data, the terminal equipment can play live broadcast in the front-end browser according to the target live broadcast data.
In this embodiment, whether data exists in a target channel is detected, where the target channel is used to store data related to a front-end browser; when data exists in the target channel, acquiring target data in the target channel; and sending the target data to the terminal equipment through the communication connection so that the terminal equipment displays the target data on a front-end browser. Therefore, the data in the target channel can be timely and actively sent to the terminal equipment through communication connection, so that the terminal equipment can timely display the front end, and the timeliness of data transmission is improved.
Further, the scheme further includes a read co-procedure operation, and the request of the terminal device is read through the read co-procedure, and before step S30, the method further includes:
performing read-co-procedure operation to detect whether the terminal equipment sends request information; if the terminal equipment sends the request information, the request information sent by the terminal equipment is read; and storing the request information sent by the terminal equipment into a first channel.
It should be understood that the server may perform a read co-procedure operation to detect whether the terminal device has transmitted the request information, read the request information when the terminal device has transmitted the request information, and continuously wait for the request information of the terminal device when the terminal device has not transmitted the request information.
It will be appreciated that in case the terminal device has transmitted the request information, the request information transmitted by the terminal device may be read and stored in the first channel.
Further, the scheme further includes a write-assisted procedure operation, and the scenario requested by the terminal device is processed through the write-assisted procedure, and before step S30, the method further includes:
performing write cooperative operation to detect whether data exists in a first channel, wherein the first channel is used for storing request information sent by terminal equipment; acquiring first data in the first channel when the data exists in the first channel; detecting a data type of the first data; and when the data type is a first preset type, storing the first data into a second channel. And when the data type is a second preset type, performing heartbeat detection according to the first data. And closing the communication connection when the data type is a third preset type.
It should be noted that, referring to fig. 4, the first preset type in the present embodiment may be an msg type, the second preset type may be a ping type, and the third preset type may be a close type.
It should be appreciated that the server may perform a write-co-procedure to detect whether data is present in the first channel, where the data is present in the first channel may be referred to as first data. First data in the first channel may be acquired and a data type of the first data may be detected.
When the data type is the first data type, that is, the data type of the first data is the msg type, the first data can be stored in the second channel, and the msg data is returned by calling the method, so that the msg data is stored in the target channel.
And returning pong to perform heartbeat detection when the data type is the second data type, namely the data type of the first data is the ping type.
When the data type is the third data type, i.e. the data type of the first data is the close type, all channels may be closed and the communication connection is closed (in this embodiment the communication connection is called ws).
In this embodiment, through the read-write cooperative procedure and the write cooperative procedure operation, the server can timely read the request information of the terminal device and make corresponding feedback, so that the real-time performance of data transmission is further improved, and a better data transmission effect can be achieved.
In an embodiment, as shown in fig. 5, a third embodiment of the data transmission method according to the present invention is provided based on the first embodiment or the second embodiment, and in this embodiment, the description is based on the first embodiment, and before the step S30, the method further includes:
step S01, timing task cooperative operation is performed to detect whether data exists in the second channel.
It should be noted that the scheme also includes timing task cooperative operation, and the scenario of active pushing by the timing task cooperative processing server is included.
It should be appreciated that the server may perform a timed task co-program operation to detect whether data is present in the second channel, wait for the second channel to acquire data if no data is present in the second channel, and assign a value to a parameter of the timed task.
Step S02, when data exists in the second channel, acquiring the current time.
It should be appreciated that in the case where there is data in the second channel, the current time may be acquired, and the last data generation time corresponding to the second channel is acquired, and the interval time is calculated according to the current time and the last data generation time.
It will be appreciated that the interval time may be compared with a preset time, and when the interval time exceeds the preset time, it is determined that the current time meets a third preset time condition. The preset time may be set according to practical situations, for example, the preset time may be set to 30S, which is not limited in this embodiment. In a specific implementation, when the difference between the current time and the last data generation time exceeds 30S, it is determined that the timeout time is reached, that is, the current time meets a third preset time condition.
It can be understood that when the interval time does not exceed the preset time, whether the current time is a multiple of the first preset value can be further detected, and when the current time is a multiple of the first preset value, the current time is judged to meet the first preset time condition. The first preset value may be set according to practical situations, for example, the preset time may be set to 5S, which is not limited in this embodiment. In a specific implementation, when the current time is a multiple of 5S, it is determined that the current time meets a first preset time condition.
It can be understood that when the interval time does not exceed the preset time, whether the current time is a multiple of the second preset value can be further detected, and when the current time is a multiple of the second preset value, the current time is judged to meet the second preset time condition. The second preset value may be set according to practical situations, for example, the preset time may be set to 30S, which is not limited in this embodiment. In a specific implementation, when the current time is a multiple of 30S, it is determined that the current time meets a second preset time condition.
It should be understood that, since there is an overlapping portion between the multiple of 5S and the multiple of 30S, in order to achieve a better detection effect, it is preferable in this embodiment that: detecting whether the current time is a multiple of a second preset value or not, and then detecting whether the current time is a multiple of the first preset value or not. In addition, other detection sequences are possible, and the present embodiment is not limited thereto.
Step S03, when the current time accords with a first preset time condition, acquiring first browser data related to a front-end browser from a first preset database.
It should be noted that, the first preset database in this embodiment may be a redis database, or may be other devices that may implement the same or similar functions, which is not limited in this embodiment. When the current time meets the first preset time condition, the basic data required by the front-end browser can be acquired from the redis database, and the basic data is called as first browser data in the embodiment.
Step S04, storing the first browser data into a target channel.
It should be appreciated that after the first browser data is obtained, the first browser data may be stored in the target channel, waiting for the output protocol to send the data in the target channel to the terminal device.
It should be noted that, the second database in this embodiment may be an es database, or may be other devices that may implement the same or similar functions, which is not limited in this embodiment. When the current time meets the second preset time condition, the common data required by the front-end browser can be obtained from the es database, and the common data is called second browser data in the embodiment.
It should be appreciated that after the second browser data is obtained, the second browser data may be stored in the target channel awaiting the output pass to send the data in the target channel to the terminal device.
It should be noted that when the current time meets the third preset time condition, all channels may be closed, and the communication connection may be closed.
In this embodiment, a timing task cooperative operation is performed to detect whether data exists in the second channel; when data exists in the second channel, acquiring the current time; when the current time accords with a first preset time condition, acquiring first browser data related to a front-end browser from a first preset database; and storing the first browser data into a target channel. The method comprises the steps that a timing task cooperative distance processing server can be used for actively pushing a scene, data related to a front-end browser are obtained and stored in a target channel, and waiting for an output cooperative distance to send the data in the target channel to a terminal device through communication connection between the server and the terminal device.
In addition, the embodiment of the invention also provides a storage medium, wherein the storage medium stores a data transmission program, and the data transmission program realizes the steps of the data transmission method when being executed by a processor.
Because the storage medium adopts all the technical schemes of all the embodiments, the storage medium has at least all the beneficial effects brought by the technical schemes of the embodiments, and the description is omitted here.
In addition, referring to fig. 6, an embodiment of the present invention further proposes a data transmission device, where the data transmission device includes:
and the communication line module 10 is used for establishing a communication line with the terminal equipment according to the communication request when the communication request sent by the terminal equipment is received.
It should be noted that the scheme can be applied to a server and used for data transmission between the server and terminal equipment corresponding to a front-end browser. The present embodiment is applicable to various scenes, for example, the present embodiment may be applied to various scenes such as a live broadcast data transmission scene, an image data transmission scene, and a web page data transmission scene, and may also be applied to other types of scenes, which are not limited in this embodiment, and in this embodiment, a live broadcast data transmission scene is taken as an example for explanation.
It should be understood that in a live data transmission scenario, a user may use a front-end browser to perform live viewing, so the front-end browser needs to acquire live data from a server in real time according to live information selected by the user, and then parse the live data to display live video to the user.
It can be understood that, for data transmission in the above scenario, most of the prior art adopts a polling mode, and the browser sends http requests to the server at intervals, and then the server returns the latest data to the client. Whether long polling or short polling, the browser needs to initiate a request each time to acquire a result, the result has certain passivity, and the server cannot actively send data to the browser. Therefore, the data transmission by the polling method wastes the server connection resources and may affect the server performance and the live broadcast effect, i.e. the existing data transmission method cannot achieve a better data transmission effect in the scene.
It should be noted that, based on the above-mentioned problem, the data transmission is not carried out by adopting a polling mode, but by adopting a new mode, based on the mode, the browser and the server can establish persistent connection only by completing handshake once, and then both sides can send data, which fully solves the problem that the server cannot actively push data to the browser, and reflects the real-time performance of data transmission. In addition, the connection closing time can be controlled by the method, and the connection can be automatically closed as long as a certain party of the server or the client actively closes the connection. In addition, the mode has a reconnection mechanism, and reconnection can be automatically performed when connection is not enabled and is not in a closed state, so that the two parties can be ensured to successfully send data as far as possible.
It will be appreciated that based on the above-described concept, in order to establish a connection between the server and the terminal device where the front-end browser is located in this way, the server may continually monitor for a communication request, upon receipt of a communication request sent by the terminal device, establish a communication line with the terminal device in accordance with the communication request.
It is understood that a communication line can be understood as a temporary communication connection between a server and a terminal device. In order to ensure information security and achieve better data transmission effect, the server in the scheme does not directly establish communication connection with the terminal equipment for data transmission after receiving the communication request, but establishes a communication line with the terminal equipment only according to the communication request, then carries out handshake through the communication line once, establishes communication connection between the server and the terminal equipment after handshake success, and can realize two-way communication between the server and the terminal equipment through the communication connection.
And the communication connection module 20 is configured to, when receiving a handshake request sent by the terminal device through the communication line, establish a communication connection with the terminal device according to the handshake request.
It should be understood that after the terminal device and the server establish a communication line, the terminal device may send a handshake request, and the server may feedback a handshake response according to the handshake request after receiving the handshake request sent by the terminal device through the communication line, thereby completing a handshake operation between the terminal device and the server to establish a communication connection between the server and the terminal device.
It can be appreciated that after the communication connection between the server and the terminal device is established in the above manner, the subsequent data exchange can be directly realized based on the communication connection, so that the communication request is not required to be retransmitted, and the bandwidth resource is saved. The communication connection is a bi-directional communication connection, and the server and/or the terminal device may transmit data through the communication connection or receive data through the communication connection, which is not limited in this embodiment.
And the data sending module 30 is used for sending the data related to the front-end browser to the terminal equipment through the communication connection.
It should be appreciated that in the case where the above communication connection exists between the server and the terminal device, if the data associated with the front-end browser is generated in the server, the server may directly send the data associated with the front-end browser to the terminal device through the communication connection, so that the terminal device displays the data on the front-end browser. Compared with the existing polling mode, the communication connection in the scheme has a bidirectional communication function, data can be flexibly sent to the terminal equipment through the communication connection according to actual conditions without sending the data to the terminal equipment under the condition of receiving the request of the terminal equipment, so that the waste of server connection resources is avoided, and a better data transmission effect can be achieved.
In a specific implementation, for example, in a live broadcast data transmission scene, a user watches live broadcast through a front-end browser, when the user accesses a live broadcast room is detected, communication connection between a server and terminal equipment can be established through the mode, then the server can directly transmit live broadcast data related to the live broadcast to the terminal equipment through the communication connection according to actual conditions, the terminal equipment can display live broadcast content to the user according to the received live broadcast data, so that the front end can display data in real time after the back-end data are generated, and the consumption condition of server resources is small.
It should be understood that, in addition to the above effect, the communication connection in the present solution can also be flexibly closed, that is, the communication connection may be closed by a server or a terminal device, and the closing time of the connection may be controlled, so long as the server or a party of the terminal device actively closes the connection, the connection may be automatically closed. In addition, the mode has a reconnection mechanism, and when the connection is not enabled and the communication connection is not actively closed by the server or the terminal equipment, reconnection can be automatically carried out, so that the two parties can be ensured to send data as far as possible, and the condition of data transmission failure is avoided.
In this embodiment, when a communication request sent by a terminal device is received, a communication line between the terminal device and the terminal device is established according to the communication request; when a handshake request sent by the terminal equipment through the communication line is received, establishing communication connection with the terminal equipment according to the handshake request; and sending the data related to the front-end browser to the terminal equipment through the communication connection. Compared with the existing polling mode, the server and the terminal equipment in the scheme can establish the durable communication connection only by completing one-time handshake, and then both sides can send data, so that the real-time performance of data transmission is reflected, the waste of server connection resources can be avoided, and the data transmission effect is improved.
In one embodiment, the data sending module 30 is further configured to detect whether there is data in a target channel, where the target channel is used to store data related to a front-end browser; when data exists in the target channel, acquiring target data in the target channel; and sending the target data to the terminal equipment through the communication connection so that the terminal equipment displays the target data on a front-end browser.
In an embodiment, the data sending module 30 is further configured to obtain target channel information corresponding to a target channel; determining a data storage state corresponding to the target channel according to the target channel information; and detecting whether data exists in the target channel according to the data storage state.
In an embodiment, the data transmission device further includes a timing task module, configured to perform timing task cooperative operation, so as to detect whether data exists in the second channel; when data exists in the second channel, acquiring the current time; when the current time accords with a first preset time condition, acquiring first browser data related to a front-end browser from a first preset database; and storing the first browser data into a target channel.
In an embodiment, the timing task module is further configured to obtain second browser data related to the front-end browser from a second preset database when the current time meets a second preset time condition; and storing the second browser data into a target channel.
In an embodiment, the timing task module is further configured to close the communication connection when the current time meets a third preset time condition.
In an embodiment, the timing task module is further configured to obtain a last data generation time; calculating interval time according to the current time and the last data generation time; and when the interval time exceeds the preset time, judging that the current time accords with a third preset time condition.
In an embodiment, the timing task module is further configured to detect, when the interval time does not exceed a preset time, whether the current time is a multiple of a first preset value; and when the current time is a multiple of the first preset value, judging that the current time accords with a first preset time condition.
In an embodiment, the timing task module is further configured to detect, when the interval time does not exceed a preset time, whether the current time is a multiple of a second preset value; and when the current time is a multiple of the second preset value, judging that the current time meets a second preset time condition.
In an embodiment, the data transmission device further includes a read co-procedure module, configured to perform a read co-procedure operation, so as to detect whether the terminal device sends the request information; the terminal equipment sends request information, and the request information sent by the terminal equipment is read; and storing the request information sent by the terminal equipment into a first channel.
In an embodiment, the read cooperative module is further configured to continuously wait for the request information of the terminal device if the terminal device does not send the request information.
In an embodiment, the data transmission device further includes a write-cooperative module, configured to perform write-cooperative operation to detect whether data exists in a first channel, where the first channel is used to store request information sent by a terminal device; acquiring first data in the first channel when the data exists in the first channel; detecting a data type of the first data; and when the data type is a first preset type, storing the first data into a second channel.
In an embodiment, the write cooperative module is further configured to perform heartbeat detection according to the first data when the data type is a second preset type.
In an embodiment, the write-cooperative module is further configured to close the communication connection when the data type is a third preset type.
Other embodiments or specific implementation methods of the data transmission device according to the present invention may refer to the above method embodiments, and are not described herein again.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
The foregoing embodiment numbers of the present invention are merely for the purpose of description, and do not represent the advantages or disadvantages of the embodiments.
From the above description of the embodiments, it will be clear to those skilled in the art that the above-described embodiment method may be implemented by means of software plus a necessary general hardware platform, but of course may also be implemented by means of hardware, but in many cases the former is a preferred embodiment. Based on this understanding, the technical solution of the present invention may be embodied essentially or in a part contributing to the prior art in the form of a software product stored in an estimator readable storage medium (e.g. ROM/RAM, magnetic disk, optical disk) as described above, comprising instructions for causing a smart device (which may be a mobile phone, estimator, data transmission device, or network data transmission device, etc.) to perform the method according to the embodiments of the present invention.
The foregoing description is only of the preferred embodiments of the present invention, and is not intended to limit the scope of the invention, but rather is intended to cover any equivalents of the structures or equivalent processes disclosed herein or in the alternative, which may be employed directly or indirectly in other related arts.
The invention discloses A1, a data transmission method, which comprises the following steps:
when a communication request sent by a terminal device is received, a communication line between the terminal device and the communication request is established according to the communication request;
when a handshake request sent by the terminal equipment through the communication line is received, establishing communication connection with the terminal equipment according to the handshake request;
and sending the data related to the front-end browser to the terminal equipment through the communication connection.
A2, the data transmission method according to A1, wherein the sending the data related to the front-end browser to the terminal device through the communication connection comprises the following steps:
detecting whether data exists in a target channel, wherein the target channel is used for storing data related to a front-end browser;
when data exists in the target channel, acquiring target data in the target channel;
and sending the target data to the terminal equipment through the communication connection so that the terminal equipment displays the target data on a front-end browser.
A3, the data transmission method as described in A2, wherein the detecting whether the data exists in the target channel includes:
Acquiring target channel information corresponding to a target channel;
determining a data storage state corresponding to the target channel according to the target channel information;
and detecting whether data exists in the target channel according to the data storage state.
A4, the data transmission method according to A1, before the data related to the front-end browser is sent to the terminal device through the communication connection, further includes:
performing timing task cooperative operation to detect whether data exists in the second channel;
when data exists in the second channel, acquiring the current time;
when the current time accords with a first preset time condition, acquiring first browser data related to a front-end browser from a first preset database;
and storing the first browser data into a target channel.
A5, the data transmission method as described in A4, wherein after the current time is obtained, further comprises:
when the current time accords with a second preset time condition, second browser data related to the front-end browser are acquired from a second preset database;
and storing the second browser data into a target channel.
A6, the data transmission method as described in A4, wherein after the current time is obtained, the method further comprises:
And closing the communication connection when the current time accords with a third preset time condition.
A7, the data transmission method as described in A4, wherein after the current time is obtained, further comprises:
acquiring the last data generation time;
calculating interval time according to the current time and the last data generation time;
and when the interval time exceeds the preset time, judging that the current time accords with a third preset time condition.
A8, the data transmission method according to A7, after calculating the interval time according to the current time and the last data generation time, further comprises:
when the interval time does not exceed the preset time, detecting whether the current time is a multiple of a first preset value;
and when the current time is a multiple of the first preset value, judging that the current time accords with a first preset time condition.
A9, the data transmission method according to A7, after calculating the interval time according to the current time and the last data generation time, further comprises:
detecting whether the current time is a multiple of a second preset value when the interval time does not exceed the preset time;
And when the current time is a multiple of the second preset value, judging that the current time meets a second preset time condition.
A10, the data transmission method according to any of A1 to A9, before the data related to the front-end browser is sent to the terminal device through the communication connection, further comprising:
performing read-co-procedure operation to detect whether the terminal equipment sends request information;
if the terminal equipment sends the request information, the request information sent by the terminal equipment is read;
and storing the request information sent by the terminal equipment into a first channel.
A11, the data transmission method as described in A10, wherein the performing a read-co-procedure operation to detect whether the terminal device sends the request information further includes:
and if the terminal equipment does not send the request information, continuously waiting for the request information of the terminal equipment.
A12, the data transmission method according to any of A1 to A9, before the data related to the front-end browser is sent to the terminal device through the communication connection, further comprising:
performing write cooperative operation to detect whether data exists in a first channel, wherein the first channel is used for storing request information sent by terminal equipment;
Acquiring first data in the first channel when the data exists in the first channel;
detecting a data type of the first data;
and when the data type is a first preset type, storing the first data into a second channel.
A13, the data transmission method as described in A12, after detecting the data type of the first data, further comprising:
and when the data type is a second preset type, performing heartbeat detection according to the first data.
A14, the data transmission method as described in A12, after detecting the data type of the first data, further comprises:
and closing the communication connection when the data type is a third preset type.
The invention also discloses a B15 and a data transmission device, wherein the data transmission device comprises:
the communication line module is used for establishing a communication line with the terminal equipment according to the communication request when the communication request sent by the terminal equipment is received;
the communication connection module is used for establishing communication connection with the terminal equipment according to the handshake request when the handshake request sent by the terminal equipment through the communication line is received;
And the data transmitting module is used for transmitting the data related to the front-end browser to the terminal equipment through the communication connection.
The data transmission device as described in B16, wherein the data sending module is further configured to detect whether there is data in a target channel, where the target channel is used to store data related to a front-end browser; when data exists in the target channel, acquiring target data in the target channel; and sending the target data to the terminal equipment through the communication connection so that the terminal equipment displays the target data on a front-end browser.
The data transmission device as described in B17, the data sending module is further configured to obtain target channel information corresponding to a target channel; determining a data storage state corresponding to the target channel according to the target channel information; and detecting whether data exists in the target channel according to the data storage state.
B18, the data transmission device of B15, further comprising:
the timing task module is used for carrying out timing task cooperative operation so as to detect whether data exist in the second channel; when data exists in the second channel, acquiring the current time; when the current time accords with a first preset time condition, acquiring first browser data related to a front-end browser from a first preset database; and storing the first browser data into a target channel.
The invention also discloses C19, a data transmission device, the data transmission device includes: the data transmission system comprises a memory, a processor and a data transmission program stored in the memory and capable of running on the processor, wherein the data transmission program realizes the data transmission method when being executed by the processor.
The invention also discloses D20 and a storage medium, wherein the storage medium stores a data transmission program, and the data transmission program realizes the data transmission method when being executed by a processor.

Claims (10)

1. A data transmission method, the data transmission method comprising:
when a communication request sent by a terminal device is received, a communication line between the terminal device and the communication request is established according to the communication request;
when a handshake request sent by the terminal equipment through the communication line is received, establishing communication connection with the terminal equipment according to the handshake request;
and sending the data related to the front-end browser to the terminal equipment through the communication connection.
2. The data transmission method according to claim 1, wherein the transmitting the data related to the front-end browser to the terminal device through the communication connection includes:
Detecting whether data exists in a target channel, wherein the target channel is used for storing data related to a front-end browser;
when data exists in the target channel, acquiring target data in the target channel;
and sending the target data to the terminal equipment through the communication connection so that the terminal equipment displays the target data on a front-end browser.
3. The data transmission method as claimed in claim 2, wherein the detecting whether the data exists in the target channel comprises:
acquiring target channel information corresponding to a target channel;
determining a data storage state corresponding to the target channel according to the target channel information;
and detecting whether data exists in the target channel according to the data storage state.
4. The data transmission method according to claim 1, wherein before the data related to the front-end browser is transmitted to the terminal device through the communication connection, further comprising:
performing timing task cooperative operation to detect whether data exists in the second channel;
when data exists in the second channel, acquiring the current time;
when the current time accords with a first preset time condition, acquiring first browser data related to a front-end browser from a first preset database;
And storing the first browser data into a target channel.
5. The data transmission method of claim 4, wherein after the current time is obtained, further comprising:
when the current time accords with a second preset time condition, second browser data related to the front-end browser are acquired from a second preset database;
and storing the second browser data into a target channel.
6. The data transmission method of claim 4, wherein after the current time is obtained, further comprising:
and closing the communication connection when the current time accords with a third preset time condition.
7. The data transmission method of claim 4, wherein after the current time is obtained, further comprising:
acquiring the last data generation time;
calculating interval time according to the current time and the last data generation time;
and when the interval time exceeds the preset time, judging that the current time accords with a third preset time condition.
8. A data transmission device, characterized in that the data transmission device comprises:
the communication line module is used for establishing a communication line with the terminal equipment according to the communication request when the communication request sent by the terminal equipment is received;
The communication connection module is used for establishing communication connection with the terminal equipment according to the handshake request when the handshake request sent by the terminal equipment through the communication line is received;
and the data transmitting module is used for transmitting the data related to the front-end browser to the terminal equipment through the communication connection.
9. A data transmission apparatus, characterized in that the data transmission apparatus comprises: a memory, a processor and a data transmission program stored on the memory and executable on the processor, which when executed by the processor implements the data transmission method according to any one of claims 1 to 7.
10. A storage medium having stored thereon a data transmission program which, when executed by a processor, implements the data transmission method according to any one of claims 1 to 7.
CN202111624373.2A 2021-12-27 2021-12-27 Data transmission method, device, equipment and storage medium Pending CN116366619A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111624373.2A CN116366619A (en) 2021-12-27 2021-12-27 Data transmission method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111624373.2A CN116366619A (en) 2021-12-27 2021-12-27 Data transmission method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN116366619A true CN116366619A (en) 2023-06-30

Family

ID=86914684

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111624373.2A Pending CN116366619A (en) 2021-12-27 2021-12-27 Data transmission method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN116366619A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117573390A (en) * 2023-11-20 2024-02-20 航天信息(广东)有限公司 Data processing method, cloud, client and data processing system

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117573390A (en) * 2023-11-20 2024-02-20 航天信息(广东)有限公司 Data processing method, cloud, client and data processing system

Similar Documents

Publication Publication Date Title
CN107566786B (en) Method and device for acquiring monitoring video and terminal equipment
US8769116B2 (en) Full-duplex bi-directional communication over a remote procedure call based communications protocol, and applications thereof
CN108833950B (en) Barrage message issuing method, server, system and storage medium
US8271580B2 (en) Mobile communication network system and server apparatus
CN110808948B (en) Remote procedure calling method, device and system
US20180048715A1 (en) Information transmitting method and apparatus in robot operating system
CN108055311B (en) HTTP asynchronous request method, device, server, terminal and storage medium
CN114039703B (en) Data transmission method, device, equipment and medium
US20180234287A1 (en) Method and apparatus of performing simultaneous multi-agent access for command execution through a single client
EP2765741A1 (en) Download method and system by way of broadcast in ubiquitous network
CN115002016B (en) Message processing system, method, device and storage medium
CN114153698B (en) Display monitoring method, device, electronic equipment and readable storage medium
CN107493486B (en) Method, system and terminal equipment for video playing termination
US9407715B2 (en) Method and system for information exchange utilizing an asynchronous persistent store protocol
CN110213330B (en) Pre-push system, method, device, electronic equipment and computer readable medium
CN102025730B (en) Data transmission device based on HTTP protocol and implementation method thereof
CN113315846A (en) Data transmission method and device
CN108881493A (en) A kind of Task Progress information-pushing method, device and equipment
CN102984138B (en) A kind of methods, devices and systems obtaining object
CN116366619A (en) Data transmission method, device, equipment and storage medium
CN108924773B (en) Message processing method and device
US20200274786A1 (en) Apparatus and method for managing message transmission delay
CN106899652B (en) Method and device for pushing service processing result
CN113204440B (en) Message sending method, device, electronic equipment and storage medium
CN113872914B (en) Data transmission method, system, control device, network device and media device

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