CN109040296B - Data pushing method and system based on long connection - Google Patents
Data pushing method and system based on long connection Download PDFInfo
- Publication number
- CN109040296B CN109040296B CN201811005328.7A CN201811005328A CN109040296B CN 109040296 B CN109040296 B CN 109040296B CN 201811005328 A CN201811005328 A CN 201811005328A CN 109040296 B CN109040296 B CN 109040296B
- Authority
- CN
- China
- Prior art keywords
- browser
- server
- long connection
- data
- 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
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/14—Session management
- H04L67/141—Setup of application sessions
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/50—Network services
- H04L67/55—Push-based network services
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/50—Network services
- H04L67/60—Scheduling or organising the servicing of application requests, e.g. requests for application data transmissions using the analysis and optimisation of the required network resources
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Information Transfer Between Computers (AREA)
Abstract
The embodiment of the invention discloses a data pushing method and a system based on long connection, wherein the method comprises the following steps: receiving a request for establishing long connection sent by a browser; according to the request, selecting a server to establish long connection with the browser; and feeding back corresponding data information to the browser according to the updating condition of the data in the server. According to the technical scheme, after the server is in long connection with the browser, corresponding data information is fed back to the browser according to the updating condition of the data in the server instead of directly feeding back the long connection state to the browser, so that timely updating of the data on the browser is effectively guaranteed, delay of data updating is avoided, the latest data in the server is effectively guaranteed to be displayed to a user on the browser, and the user experience effect is greatly improved.
Description
Technical Field
The invention relates to the technical field of data pushing in a B/S architecture, in particular to a data pushing method and system based on long connection.
Background
In the existing B/S architecture, an HTTP protocol is mainly used, and the HTTP protocol uses a "request and response" mode, that is, a browser sends a request, and after receiving the request sent by the browser, a server pushes up the latest data to the browser, that is, a user needs to actively refresh to request the browser to obtain the latest data.
As can be seen from the above description, when the browser does not send a request to the server, and the browser has updated data related to the browser (e.g., data displayed on a browser page), the data displayed on the client is not the latest data, and in some service scenarios, the user experience may be affected. For example, in the e-commerce platform, when a user views and reaches a commodity price or quantity through a browser, before placing an order, the price or quantity of the commodity in a server is updated, so that the quantity or price of the commodity viewed on the browser by the user when placing the order is different, the price when the user purchases is different from the viewed price or the user cannot purchase the product directly, and the user experience is influenced to a great extent.
In summary, in the B/S architecture in the prior art, a data pushing method and system that enable the data displayed by the browser to be the latest data in the server corresponding to the browser are absent.
Disclosure of Invention
The embodiment of the invention provides a data pushing method and system based on long connection, and aims to solve the technical problem that a data pushing method capable of automatically updating data is lacked in the prior art.
The embodiment of the invention provides a data pushing method based on long connection, which is applied to a server side and comprises the following steps:
receiving a request for establishing long connection sent by a browser;
according to the request, selecting a server to establish long connection with the browser;
and feeding back corresponding data information to the browser according to the updating condition of the data in the server.
In one embodiment, the feeding back corresponding data information to the browser according to the update condition of the data in the server includes:
if the data related to the browser in the server is updated within a preset time period, pushing the updated data to the browser:
and if the data related to the browser in the server is not updated within a preset time period, sending the long connection state to the browser.
In one embodiment, after the selecting the server to establish the long connection with the browser, the method further includes:
and storing the long connection state established between the selected server and the browser in a distributed cache.
In an embodiment, the storing the long connection state established between the selected server and the browser in a distributed cache specifically includes:
and storing the connection state in the nodes of the distributed cache by adopting a Hash value algorithm.
In one embodiment, before the receiving the request for establishing the long connection sent by the browser, the method further includes:
registration of a current page of a browser is received.
The data pushing method based on the long connection provided by the embodiment of the invention is applied to a browser end and comprises the following steps:
sending a request for establishing long connection with a server;
establishing a long connection with the server according to the request;
receiving corresponding data information sent by the server;
after the operation on the relevant information is finished, the request for establishing the long connection with the server is sent again.
In an embodiment, the receiving the related data sent by the server specifically includes:
within a preset time period, if the data related to the browser in the server is updated, receiving the updated data;
and receiving the state data of the long connection if the data related to the browser in the server is not updated in a preset time period.
In one embodiment, before sending the request for establishing the long connection with the server, the method further comprises:
and when the connection between the browser and the push server is normal, registering the current page of the browser to the server.
The data pushing system based on the long connection provided by the embodiment of the invention is applied to a server side and comprises the following components:
the first receiving module is used for receiving a long connection request sent by a browser;
the first communication module is used for selecting a server to establish long connection with the browser according to the long connection request;
and the feedback module is used for feeding back corresponding data information to the browser according to the updating condition of the data in the server.
The data pushing system based on the long connection provided by the embodiment of the invention is applied to a browser end and comprises the following components:
the sending module is used for sending a request for establishing long connection with the server;
the second communication module is used for establishing long connection with the server requested by the connection request;
the second receiving module is used for receiving corresponding data information sent by a server which establishes long connection with the browser;
the sending module is further configured to send a request for establishing a long connection with the server again after the operation on the relevant information is completed.
The data pushing device based on the long connection provided by the embodiment of the invention is applied to a server side, and comprises a memory, a processor and a computer program which is stored on the memory and can run on the processor, wherein when the computer program is executed by the processor, the steps of the data pushing method based on the long connection are realized.
The data pushing device based on the long connection provided by the embodiment of the invention is applied to a browser end, and comprises a memory, a processor and a computer program which is stored on the memory and can run on the processor, wherein when the computer program is executed by the processor, the steps of the data pushing method based on the long connection are realized.
The embodiment of the invention adopts at least one technical scheme which can achieve the following beneficial effects:
according to the data pushing method based on the long connection, after a request for establishing the long connection sent by a browser is received, a server is selected to establish the long connection with the browser, and relevant data are fed back to the browser according to the updating condition of the data relevant to the browser in the server. According to the scheme, after the server is in long connection with the browser, the updating condition of the data related to the browser is directly sent, so that the timely updating of the data on the browser is effectively guaranteed, the delay of the data updating is avoided, the latest data displayed for a user on the browser in the server is effectively guaranteed, and the user experience effect is greatly improved.
Drawings
The accompanying drawings, which are included to provide a further understanding of the invention and are incorporated in and constitute a part of this specification, illustrate embodiments of the invention and together with the description serve to explain the invention and not to limit the invention. In the drawings:
fig. 1 is a flowchart of a data pushing method based on long connection according to an embodiment of the present invention;
FIG. 2 is a diagram illustrating a browser establishing a long connection with a corresponding server according to an embodiment of the present invention;
fig. 3 is a flowchart of a data pushing method based on long connection according to an embodiment of the present invention;
FIG. 4 is a diagram illustrating a server feeding back updated data information to a browser according to an embodiment of the present invention;
FIG. 5 is a diagram illustrating a server feeding back a long connection status to a browser according to an embodiment of the present invention;
fig. 6 is a flowchart of a data pushing method based on long connection according to an embodiment of the present invention;
FIG. 7 is a flowchart of a data pushing method based on long connection according to an embodiment of the present invention;
FIG. 8 is a flowchart of a data pushing method based on long connection according to an embodiment of the present invention;
fig. 9 is a flowchart of a data pushing method based on long connection according to an embodiment of the present invention;
FIG. 10 is a block diagram of a data push system based on long connections according to an embodiment of the present invention;
fig. 11 is a block diagram of a data push system based on long connection according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the technical solutions of the present invention will be clearly and completely described below with reference to the specific embodiments of the present invention and the accompanying drawings. It is to be understood that the described embodiments are merely exemplary of the invention, and not restrictive of the full scope of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The technical solutions provided by the embodiments of the present invention are described in detail below with reference to the accompanying drawings.
Referring to fig. 1, an embodiment of the present invention discloses a data pushing method based on long connection, which is applied to a server side, and the method mainly includes:
step S12, receiving a request for establishing long connection sent by a browser end;
in the embodiment of the invention, before the server establishes the long connection with the browser, the server first receives a request sent by the browser for establishing the long connection with the browser.
The request sent by the browser to establish the long connection may be sent along with the data request sent by the browser.
In the embodiment of the invention, the data which needs to be updated by the browser in time is stored in the server, and the data which is updated in real time is displayed to the user through the browser. For example, in the e-commerce platform, the information of the goods, such as price, quantity and the like, is updated in real time, and the updated data is displayed to the user through the browser
Step S14, according to the request, selecting a server to establish long connection with the browser;
in the embodiment of the present invention, different data may be stored in different servers, and when a request for establishing a long connection sent by a browser is received, a server corresponding to the request may be selected to establish the long connection with the browser, that is, a server is selected according to a storage location of the data requested in the long connection request to establish the long connection with the browser.
If the data requested by the received request for establishing long connection with the browser a is data A and the data A is stored in a server AA, establishing long connection between the browser a and the server AA according to the storage position (server AA) of the data A requested by the received request; when the data requested by the received request for establishing the long connection from server B is data B and data B is stored in server BB, the browser B and server BB establish the long connection according to the storage location of data B (server BB) requested by the received request, as shown in fig. 2.
And step S16, feeding back relevant data information to the browser according to the updating condition of the data in the server.
In the embodiment of the invention, after receiving a request for establishing long connection sent by a browser, a server side selects a matched server to be connected with the browser according to the request, and after the connection between the browser and the server is completed, the server side does not immediately feed back connection state information to the browser, but feeds back corresponding data information to the server according to the updating condition of data related to the browser and stored in the server for establishing long connection with the browser.
According to the data pushing method based on the long connection, after a request for establishing the long connection sent by a browser is received, a server is selected to establish the long connection with the browser, and corresponding data information is pushed to the browser according to the updating condition of data related to the browser in the server. According to the technical scheme, the browser is in long connection with the server, and the server directly sends the data information corresponding to the browser after the long connection with the browser is established, so that timely updating of the data on the browser is effectively guaranteed, delay of data updating is avoided, the latest data in the server is effectively guaranteed to be displayed to a user on the browser, and the user experience effect is greatly improved.
Referring to fig. 3, in an embodiment, the step S16 specifically includes:
step S161, if the data related to the browser in the server is updated within a preset time period, feeding the updated data back to the browser:
in the embodiment of the invention, after the server establishes the long connection with the browser, data such as the long connection state and the like are not fed back to the browser immediately, but whether the data related to the browser stored in the server is updated or not is checked after a preset time period, and if the data is updated, the updated data is fed back to the browser; for example, for the commodity numbered 01, the price is 500 yuan, and for reasons such as season change and warehouse clearing, the price is adjusted at present, the unit price is adjusted from 500 yuan to 250 yuan, and at 0.1s before the price update, a data request for establishing a long connection sent by the browser C is received, and if the preset time interval is 0.2s, the server storing the price of the commodity numbered 01 feeds back the updated data information (the price of the commodity numbered 01) to the browser C at 0.1s after the price update of the commodity. See in particular the schematic diagram shown in fig. 4.
And step S162, if the data related to the browser in the server is not updated in a preset time period, sending the long connection state to the browser.
Referring to fig. 5, if the time interval is 0.2s and the data related to the browser D in the server corresponding to the browser D is not updated within 0.2s after the browser D sends the request for establishing the long connection, the browser D sends the long connection state to the browser D after 0.2 s. See in particular fig. 5.
In one embodiment, referring to fig. 6, after the step S14, the method further includes:
and step S15, storing the long connection state established between the selected server and the browser in a distributed cache.
In the embodiment of the invention, after a specific server is selected to establish a long connection with a browser, the established state of the long connection is stored in a distributed cache, and if the server establishing the long connection with the browser does not update data related to the browser after a preset time interval, the long connection state is called from the distributed cache and fed back to the browser.
In an embodiment, the step S15 specifically includes:
and storing the connection state in the nodes of the distributed cache by adopting a hash value algorithm.
In the embodiment of the present invention, the distributed cache may include a plurality of nodes, and specifically, the node in which the long connection state is stored may be determined according to a hash value algorithm, and the specific method is as follows:
firstly, numbering a server and a node respectively, numbering the server and the node by adopting an integer starting from 1, and taking the number of the server as a key value; numbering the nodes by using integers starting from 0; then, key% n (the number of nodes) is calculated, and if the obtained value is several, the connection state between the server and the browser corresponding to the number is stored in the node with the corresponding number.
In the embodiment of the invention, a hash value algorithm is adopted to determine the node in which the connection state of the server and the browser is specifically stored, so that the storage capacity of each node is effectively balanced.
In one embodiment, before receiving a request sent by a browser to establish a long connection, the method further comprises:
and step S11, receiving the registration of the current page of the browser.
In the embodiment of the invention, before receiving the request for establishing the long connection sent by the browser, the server receives the registration request for the current page sent by the browser through Ajax to complete the registration for the current page of the browser, so that the server and the browser establish a relationship. This relationship may be, but is not limited to, a browser to server correspondence.
In this embodiment of the present invention, before receiving registration of a current page of a browser, the method further includes:
and detecting that the connection between the message push server and the browser is normal.
In the embodiment of the present invention, the corresponding feedback information is sent through the message push server, so that it is required to detect whether the connection between the message push server and the browser is normal, and only in a normal case, the message push server can push the corresponding feedback information (updated data or long connection status) to the browser.
Corresponding to the data pushing method based on long connection at the server side, an embodiment of the present invention further provides a data pushing method based on long connection applied to a browser side, and fig. 7 shows the data pushing method based on long connection applied to the browser side in an embodiment of the present invention, and as shown in fig. 7, the method includes:
step S22, sending a request for establishing long connection with the server;
step S24, according to the request, establishing long connection with the server;
step S26, receiving the relevant information sent by the server;
step S28, after the operation on the relevant information is finished, the request for establishing long connection with the server is sent again.
In an embodiment, referring to fig. 8, the step S26 specifically includes:
step S261, in a preset time period, if the data related to the browser in the server is updated, receiving the updated data;
step S262, in a preset time period, if the data related to the browser in the server is not updated, receiving the status data of the long connection.
In one embodiment, if the related data information is updated data, the operation on the updated data may be processing such as displaying, and after the operation on the updated data is finished, the request for establishing a long connection with the server is continuously sent; if the relevant data information is in the long connection state, the request for establishing the long connection can be continuously sent after the long connection state is received.
In one embodiment, referring to fig. 9, before step S22, the method further comprises:
and step S21, registering the current page of the browser to the server.
And when the connection between the browser and the push server is normal, registering the current page of the browser to the server.
In one embodiment, the browser sends a request through Ajax to detect whether its connection with the message push server is normal. The request sent by the browser through Ajax may be a heartbeat detection request. And if the heartbeat detection request is normal, indicating that the connection between the browser and the message push server is normal.
The data pushing method based on the long connection provided by the embodiment of the invention is applied to a browser end, and the browser end receives corresponding data information sent by a server instead of directly receiving a connection state after sending a request for establishing the long connection with the server and establishing the long connection with the server. After receiving the related information sent by the server and completing the related operation, the method continues to send a request for establishing long connection to the server, thus effectively ensuring that the data information displayed by the browser end is the latest data information in the server, and avoiding the technical problem that a user needs to actively refresh the browser each time the latest data in the server needs to be obtained in the B/S framework in the prior art.
Corresponding to the above data pushing method based on long connection applied to the server, an embodiment of the present invention further provides a data pushing system based on long connection, fig. 8 is a block diagram of the data pushing system based on long connection in an embodiment of the present invention, and as shown in fig. 10, the system includes:
a first receiving module 102, configured to receive a long connection request sent by a browser;
the first communication module 104 is configured to select a server to establish a long connection with the browser according to the long connection request;
and the feedback module 106 is configured to feed back corresponding data information to the browser according to the update condition of the data in the server.
In one embodiment, the push module comprises a first push unit and a second push unit;
the first pushing unit is configured to, if data related to the browser in the server is updated within a preset time period, feed the updated data back to the browser:
the second pushing unit is configured to feed back a long connection state to the browser if data related to the browser in the server is not updated within a preset time period.
In one embodiment, the system further comprises:
and the storage module is used for storing the long connection state established between the selected server and the browser in a distributed cache.
In one embodiment, the storage module stores the connection state in a node of a distributed cache using a hash algorithm.
In an embodiment, the first receiving module 102 is further configured to receive registration of a current page of a browser.
The data pushing system based on the long connection provided by the embodiment of the invention can be applied to a server side, and the feedback module feeds back corresponding data information to the browser according to the updating condition of the data in the server instead of directly feeding back the state information of the connection to the browser.
Corresponding to the above data pushing method based on long connection applied to the browser end, an embodiment of the present invention further provides a data pushing system based on long connection, and fig. 11 is a block diagram of the data pushing system based on long connection in an embodiment of the present invention, and as shown in fig. 11, the system includes:
a sending module 112, configured to send a request for establishing a long connection with a server;
a second communication module 114, configured to establish a long connection with the server requested by the connection request;
a second receiving module 116, configured to receive corresponding data information sent by a server that establishes a long connection with a browser;
the sending module 112 is further configured to send the request for establishing the long connection with the server again after the operation on the relevant information is completed.
In one embodiment, the receiving module 116 includes a first receiving unit and a second receiving unit:
the first receiving unit is configured to receive, within a preset time period, updated data in the server if the data related to the browser is updated;
the second receiving unit is configured to receive the status data of the long connection if the data related to the browser in the server is not updated within a preset time period.
In one embodiment, the system further comprises:
and the registration module is used for registering the current page of the browser to the server when the connection between the browser and the push server is normal.
In the data pushing system based on long connection applied to the browser end, provided by the embodiment of the invention, after the sending module sends the request for establishing long connection with the server, the second communication module establishes long connection with the server, the receiving module receives corresponding data information sent by the server for establishing long connection with the browser, and after the operation on the corresponding data information is completed, the request for establishing long connection is continuously sent. Therefore, the latest data information in the server can be effectively displayed on the current page of the browser, and the problem that the user experience is influenced due to the delay of the information displayed by the browser is effectively solved.
Corresponding to the above data pushing method and system based on long connection applied to the server, an embodiment of the present invention provides a data pushing device based on long connection, which is applied to the server, and includes a memory, a processor, and a computer program stored in the memory and capable of running on the processor, where when the computer program is executed by the processor, the following processes can be implemented:
receiving a request for establishing long connection sent by a browser;
according to the request, selecting a server to establish long connection with the browser;
and feeding back corresponding data information to the browser according to the updating condition of the data in the server.
Alternatively, the computer application program, when executed by the processor,
the feeding back corresponding data information to the browser according to the update condition of the data in the server includes:
if the data related to the browser in the server is updated within a preset time period, feeding the updated data back to the browser:
and if the data related to the browser in the server is not updated within a preset time period, feeding back the long connection state to the browser.
Alternatively, the computer application program, when executed by the processor,
after the long connection is established between the selection server and the browser, the method further comprises the following steps:
and storing the long connection state established between the selected server and the browser in a distributed cache.
Alternatively, the computer application program, when executed by the processor,
the storing the long connection state established between the selected server and the browser in a distributed cache specifically includes:
and storing the connection state in the nodes of the distributed cache by adopting a hash value algorithm.
Alternatively, the computer application program, when executed by the processor,
before the receiving the request for establishing the long connection sent by the browser, the method further includes:
registration of a current page of a browser is received.
According to the data pushing device based on the long connection applied to the server side, after the processor receives the operation of the request for establishing the long connection sent by the browser, the processor executes the operation of selecting the server to establish the long connection with the browser, and pushes the relevant data to the browser according to the updating condition of the data relevant to the browser in the server. According to the scheme, after the operation that the server establishes long connection with the browser is executed, the processor executes the operation of feeding back corresponding data information to the browser according to the updating condition of the data related to the browser. Therefore, timely updating of data on the browser is effectively guaranteed, delay of data updating is avoided, the fact that the data displayed to a user on the browser are the latest data in the server is effectively guaranteed, and the user experience effect is greatly improved.
Corresponding to the above method and system for pushing data based on long connection applied to the browser end, an embodiment of the present invention provides a data pushing device based on long connection, which is applied to the browser end, and includes a memory, a processor, and a computer program stored in the memory and capable of running on the processor, where when the computer program is executed by the processor, the following procedures can be implemented:
sending a request for establishing long connection with a server;
establishing a long connection with the server according to the request;
receiving corresponding data information fed back by the server;
after the operation on the relevant information is finished, the request for establishing the long connection with the server is sent again.
Alternatively, the computer program, when executed by a processor,
the receiving of the relevant data sent by the server specifically includes:
within a preset time period, if the data related to the browser in the server is updated, receiving the updated data;
and receiving the state data of the long connection if the data related to the browser in the server is not updated in a preset time period.
Alternatively, the computer program, when executed by a processor,
before sending the request for establishing the long connection with the server, the method further comprises the following steps:
and when the connection between the browser and the push server is normal, registering the current page of the browser to the server.
According to the data pushing device based on the long connection, provided by the embodiment of the invention, after the browser end sends the request for establishing the long connection with the server and establishes the long connection with the server, the processor executes the operation of receiving the relevant information sent by the server instead of directly receiving the connection state. After receiving the related information sent by the server and completing the related operation, the operation of sending the request for establishing the long connection to the server in a short time is continuously executed, so that the data information displayed by the browser end is effectively ensured to be the latest data information in the server, and the technical problem that a user needs to actively refresh the browser every time the latest data in the server needs to be obtained in a B/S framework in the prior art is solved.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
It should also be noted that 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 an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The above description is only an example of the present invention, and is not intended to limit the present invention. Various modifications and alterations to this invention will become apparent to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the scope of the claims of the present invention.
Claims (10)
1. A data push method based on long connection is applied to a server side, and is characterized by comprising the following steps:
receiving a request for establishing long connection sent by a browser;
according to the request, selecting a server to establish long connection with the browser; when a request for establishing a long connection sent by a browser end is received, selecting a server corresponding to the request to establish the long connection with the browser, namely selecting the server according to the storage position of the data requested in the long connection request to establish the long connection with the browser;
storing the long connection state established between the selected server and the browser in a distributed cache, and if the server establishing the long connection with the browser does not update data related to the browser after a preset time interval, calling the long connection state from the distributed cache and feeding the long connection state back to the browser;
feeding corresponding data information back to the browser according to the updating condition of the data in the server;
the storing the long connection state established between the selected server and the browser in a distributed cache specifically includes:
storing the connection state in nodes of a distributed cache by adopting a Hash value algorithm; the distributed cache comprises a plurality of nodes, the long connection state is specifically stored in which node, and the determination is carried out according to a hash value algorithm, and the specific method comprises the following steps:
firstly, numbering a server and a node respectively, numbering the server and the node by adopting an integer starting from 1, and taking the number of the server as a key value; numbering the nodes by using integers starting from 0; then, key% n (the number of nodes) is calculated, and if the obtained value is several, the connection state between the server and the browser corresponding to the number is stored in the node with the corresponding number.
2. The method according to claim 1, wherein the feeding back corresponding data information to the browser according to the update condition of the data in the server comprises:
if the data related to the browser in the server is updated within a preset time period, feeding the updated data back to the browser:
and if the data related to the browser in the server is not updated within a preset time period, feeding back the long connection state to the browser.
3. The method of claim 1, wherein before receiving the request sent by the browser to establish the long connection, the method further comprises:
registration of a current page of a browser is received.
4. A data pushing method based on long connection, which is applied to a browser end and used in cooperation with the data pushing method based on long connection as claimed in claim 1, and which comprises:
sending a request for establishing long connection with a server;
establishing a long connection with the server according to the request;
receiving corresponding data information fed back by the server;
after the operation on the relevant information is finished, the request for establishing the long connection with the server is sent again.
5. The method according to claim 4, wherein the receiving the corresponding data-in-data information fed back by the server specifically includes:
within a preset time period, if the data related to the browser in the server is updated, receiving updated data fed back by the server;
and in a preset time period, if the data related to the browser in the server is not updated, receiving state data fed back by the server in a long connection state.
6. The method of claim 5, further comprising, prior to sending the request to establish the long connection with the server:
and when the connection between the browser and the push server is normal, registering the current page of the browser to the server.
7. A data push system based on long connection is applied to a server side and is characterized by comprising:
the first receiving module is used for receiving a long connection request sent by a browser;
the first communication module is used for selecting a server to establish long connection with the browser according to the long connection request; when a request for establishing a long connection sent by a browser end is received, selecting a server corresponding to the request to establish the long connection with the browser, namely selecting the server according to the storage position of the data requested in the long connection request to establish the long connection with the browser;
the feedback module is used for feeding back corresponding data information to the browser according to the updating condition of the data in the server;
a storage module, configured to store a long connection state established between the selected server and the browser in a distributed cache, and if the server establishing the long connection with the browser does not update data related to the browser after a preset time interval, retrieve the long connection state from the distributed cache and feed the long connection state back to the browser
The storage module stores the connection state in nodes of a distributed cache by adopting a hash value algorithm; storing the connection state in nodes of a distributed cache by adopting a Hash value algorithm; the distributed cache comprises a plurality of nodes, the long connection state is specifically stored in which node, and the determination is carried out according to a hash value algorithm, and the specific method comprises the following steps:
firstly, numbering a server and a node respectively, numbering the server and the node by adopting an integer starting from 1, and taking the number of the server as a key value; numbering the nodes by using integers starting from 0; then, key% n (the number of nodes) is calculated, and if the obtained value is several, the connection state between the server and the browser corresponding to the number is stored in the node with the corresponding number.
8. A long connection based data push system for use in a browser end in conjunction with the long connection based data push system of claim 7, comprising:
the sending module is used for sending a request for establishing long connection with the server;
the second communication module is used for establishing long connection with the server requested by the connection request;
the second receiving module is used for receiving corresponding data information sent by a server which establishes long connection with the browser;
the sending module is further configured to send a request for establishing a long connection with the server again after the operation on the relevant information is completed.
9. A data pushing device based on long connection, applied to a server side, comprising a memory, a processor and a computer program stored on the memory and operable on the processor, wherein the computer program, when executed by the processor, implements the steps of the data pushing method based on long connection according to any one of claims 1 to 3.
10. A data pushing device based on long connection, applied to a browser end, comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the data pushing method based on long connection according to any one of claims 4 to 6.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811005328.7A CN109040296B (en) | 2018-08-30 | 2018-08-30 | Data pushing method and system based on long connection |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811005328.7A CN109040296B (en) | 2018-08-30 | 2018-08-30 | Data pushing method and system based on long connection |
Publications (2)
Publication Number | Publication Date |
---|---|
CN109040296A CN109040296A (en) | 2018-12-18 |
CN109040296B true CN109040296B (en) | 2021-04-06 |
Family
ID=64626395
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201811005328.7A Active CN109040296B (en) | 2018-08-30 | 2018-08-30 | Data pushing method and system based on long connection |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN109040296B (en) |
Families Citing this family (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113364830B (en) * | 2021-04-26 | 2023-07-07 | 福建天泉教育科技有限公司 | Long-link cache optimization method and system |
CN115913944A (en) * | 2022-10-31 | 2023-04-04 | 中国工商银行股份有限公司 | Data updating method, device, equipment, medium and program product |
Citations (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102333128A (en) * | 2011-10-31 | 2012-01-25 | 河南省电力公司计量中心 | Active transmission method for real-time Web data |
CN103716371A (en) * | 2013-10-31 | 2014-04-09 | 国家电网公司 | Web real-time data active pushing method |
CN103731684A (en) * | 2014-01-26 | 2014-04-16 | 飞狐信息技术(天津)有限公司 | VOD (video on demand)-LVD (live video broadcast) video switching method, device and system |
CN103780603A (en) * | 2013-12-31 | 2014-05-07 | 电子科技大学 | Lightweight push method in application |
CN104333577A (en) * | 2014-10-23 | 2015-02-04 | 张勇平 | Message pushing system and method based on HTTP |
CN104539740A (en) * | 2015-01-26 | 2015-04-22 | 北京奇艺世纪科技有限公司 | Information push method and device |
CN106569899A (en) * | 2016-11-03 | 2017-04-19 | 努比亚技术有限公司 | Ajax communication system and method |
CN107248052A (en) * | 2017-05-16 | 2017-10-13 | 上海艾融软件股份有限公司 | A kind of commodity stocks information determines method, apparatus and system |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103973737A (en) * | 2013-01-30 | 2014-08-06 | 腾讯科技(深圳)有限公司 | Method, server and browser for actively pushing messages |
-
2018
- 2018-08-30 CN CN201811005328.7A patent/CN109040296B/en active Active
Patent Citations (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102333128A (en) * | 2011-10-31 | 2012-01-25 | 河南省电力公司计量中心 | Active transmission method for real-time Web data |
CN103716371A (en) * | 2013-10-31 | 2014-04-09 | 国家电网公司 | Web real-time data active pushing method |
CN103780603A (en) * | 2013-12-31 | 2014-05-07 | 电子科技大学 | Lightweight push method in application |
CN103731684A (en) * | 2014-01-26 | 2014-04-16 | 飞狐信息技术(天津)有限公司 | VOD (video on demand)-LVD (live video broadcast) video switching method, device and system |
CN104333577A (en) * | 2014-10-23 | 2015-02-04 | 张勇平 | Message pushing system and method based on HTTP |
CN104539740A (en) * | 2015-01-26 | 2015-04-22 | 北京奇艺世纪科技有限公司 | Information push method and device |
CN106569899A (en) * | 2016-11-03 | 2017-04-19 | 努比亚技术有限公司 | Ajax communication system and method |
CN107248052A (en) * | 2017-05-16 | 2017-10-13 | 上海艾融软件股份有限公司 | A kind of commodity stocks information determines method, apparatus and system |
Also Published As
Publication number | Publication date |
---|---|
CN109040296A (en) | 2018-12-18 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US8838904B2 (en) | Method, system and server of removing a distributed caching object | |
US20140087709A1 (en) | Associating a particular account configuration during the out of box experience for a mobile device | |
US10425502B2 (en) | System and method for acquiring, processing and updating global information | |
US20200036812A1 (en) | Resource Download Method, Electronic Device, and Apparatus | |
CN112131504B (en) | Webpage editing and displaying method, device, equipment and storage medium | |
US20240273508A1 (en) | Method, apparatus, and device for accessing aggregation code payment page, and medium | |
CN109040296B (en) | Data pushing method and system based on long connection | |
CN107357557B (en) | Information updating method and device | |
WO2017118318A1 (en) | Data storage and service processing method and device | |
JP6903570B2 (en) | Information manipulation | |
CN107220260B (en) | Page display method and device | |
CN107295052B (en) | Service processing method and device | |
CN110943876B (en) | URL state detection method, device, equipment and system | |
CN112437155B (en) | Service data processing method and device and server device | |
CN113687940B (en) | Load balancing method and device and physical machine | |
CN106156185B (en) | Method, device and system for inquiring service request execution state | |
CN115277816B (en) | Service adaptation method, device, system and computer readable medium | |
CN112036974A (en) | Service commodity online method, device, equipment and storage medium | |
JP6553650B2 (en) | Data processing method and system | |
CN111814014B (en) | Information interaction method, device and storage medium | |
CN110968754B (en) | Detection method and device for crawler page turning strategy | |
CN110968453A (en) | Data storage method and device | |
CN110968599B (en) | Inquiry method and device based on Impala | |
CN105159901B (en) | Proxy protocol searching method and device | |
CN117670426A (en) | State synchronization method, state determination device, processor and storage medium |
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 |