CN107800585B - Network communication method and device, and message pushing method and device - Google Patents
Network communication method and device, and message pushing method and device Download PDFInfo
- Publication number
- CN107800585B CN107800585B CN201610807978.8A CN201610807978A CN107800585B CN 107800585 B CN107800585 B CN 107800585B CN 201610807978 A CN201610807978 A CN 201610807978A CN 107800585 B CN107800585 B CN 107800585B
- Authority
- CN
- China
- Prior art keywords
- long connection
- server
- client
- message
- establishing
- 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
- H04L43/00—Arrangements for monitoring or testing data switching networks
- H04L43/08—Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters
- H04L43/0805—Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters by checking availability
- H04L43/0811—Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters by checking availability by checking connectivity
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L51/00—User-to-user messaging in packet-switching networks, transmitted according to store-and-forward or real-time protocols, e.g. e-mail
- H04L51/21—Monitoring or handling of messages
- H04L51/214—Monitoring or handling of messages using selective forwarding
-
- 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
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Environmental & Geological Engineering (AREA)
- Telephonic Communication Services (AREA)
Abstract
The embodiment of the invention discloses a method and a device for network communication and a method and a device for pushing messages. The method provided by the embodiment of the invention comprises the following steps: detecting whether a first long connection is established between the server and the server; when a first long connection with a server is detected to be established, monitoring the state of the first long connection; and when the disconnection of the first long connection is monitored, establishing a second long link with the server.
Description
Technical Field
The present invention relates to the field of communications technologies, and in particular, to a method and an apparatus for network communication, and a method and an apparatus for pushing a message.
Background
Push (Push) service is a content distribution mechanism, which adopts a client/server mode, and the server can actively distribute the content required by the client to the client without the client sending a request. The Push path refers to a network path used by the server for pushing data to the client, and the implementation technology used for establishing the Push path is based on a specific application scenario.
The long connection is one of push paths, and is characterized in that the client always keeps a connection with the server during operation, so that the server pushes messages to the client by adopting the long connection at any time. The advantage of using long connection is that the instantaneity is good, and the management difficulty of the server to the client is low. In the prior art, only one long connection is established between a client and a server, and if the long connection is disconnected due to some reasons, the real-time performance of data cannot be guaranteed, so that the reliability of a push path is low.
Disclosure of Invention
The embodiment of the invention provides a network communication method and device and a message pushing method and device, which can improve the reliability of a push path.
In a first aspect, an embodiment of the present invention provides a method for network communication, including:
detecting whether a first long connection is established between the server and the server;
when a first long connection with a server is detected to be established, monitoring the state of the first long connection;
and when the disconnection of the first long connection is monitored, establishing a second long link with the server.
In a second aspect, an embodiment of the present invention provides a method for pushing a message, including:
when a first long connection established with a client is disconnected and an establishment request sent by the client is received, establishing a second long connection with the client;
and pushing a message to the client through the second long connection.
In a third aspect, an embodiment of the present invention provides an apparatus for network communication, including:
the detection module is used for detecting whether a first long connection is established between the detection module and the server;
the monitoring module is used for monitoring the state of a first long connection when the first long connection with the server is established;
and the establishing module is used for establishing a second long link with the server when the disconnection of the first long link is monitored.
In a fourth aspect, an embodiment of the present invention provides an apparatus for pushing a message, including:
the system comprises an establishing module, a sending module and a receiving module, wherein the establishing module is used for establishing a first long connection with a client and establishing a second long connection with the client when the first long connection established with the client is disconnected and an establishing request sent by the client is received;
and the pushing module is used for pushing the message to the client through the second long connection.
According to the technical scheme, the embodiment of the invention has the following advantages:
according to the invention, when the disconnection of the first long connection between the client and the server is detected, the second long connection is established with the server, so that at least one long connection is kept between the client and the server, the real-time performance of data is ensured, and the reliability of a push channel is improved.
Drawings
FIG. 1 is a flow chart illustrating one embodiment of a method of network communication of the present invention;
FIG. 2 is a flow chart illustrating one embodiment of a method of network communication of the present invention;
FIG. 3 is a block diagram illustrating an embodiment of a push message infrastructure in accordance with the present invention;
FIG. 4 is a schematic diagram of an embodiment of a network communication device;
fig. 5 is a schematic structural diagram of an embodiment of a message pushing apparatus according to the present invention;
fig. 6 is a schematic structural diagram of an embodiment of a terminal of the present invention;
fig. 7 is a schematic structural diagram of an embodiment of a server of the present invention.
Detailed Description
Referring to fig. 1, fig. 1 is a flowchart illustrating a network communication method according to an embodiment of the invention. In this embodiment, the network communication method includes:
101. whether a first long connection is established with a server is detected.
102. When detecting that a first long connection is established with a server, monitoring the state of the first long connection.
103. And when the disconnection of the first long connection is monitored, establishing a second long link with the server.
In this embodiment, the first long connection is a long connection established between the first process in the client and the server, and the long connection is used to receive a message pushed by the server to the client. For example, the server pushes a hint message of an os update to a client that employs an os of windows7 version over a long connection. The first process to establish the first long connection with the server is typically set by default and the first long connection is typically established with the server upon startup of the first process.
A second process in the client detects the state of the first long connection. Specifically, the second process may communicate with the first process through IPC to obtain the state of the first long connection. In this embodiment, the first process and the second process are respectively of a plurality of types. Optionally, the first process is a system service in the client, and the second process is a desktop application in the client. The system service is generally operated in a background of a client, a program window or a dialog box cannot appear, and the system service can be observed only in a task manager; a desktop application refers to a process that has a program window or dialog box to interact with a user. The first process is preferably a system service because system services typically survive relatively long periods of time while the client is running, and long connections created by the server are also relatively stable.
Or, the first process or the second process may also be an independent process in the client, without an interface, and after the start, the long connection is specially created to execute the push operation, which is not limited herein.
There are several ways to monitor the first long connection. For example, when the first long connection is established, the first process also creates a target flag bit, where a value of the target flag bit at the time of creation is a default initial value (e.g., 0 or FALSE), and when the first long connection is disconnected, the first process changes a value of the target flag bit to a target value (e.g., 1 or TRUE). The second Process obtains the current value of the target mark bit in the first Process through Inter-Process Communication (IPC) to detect the state of the first long connection. There are many methods for IPC, such as a method of sharing content or a method of sending through a pipeline, and these methods are prior art and are not described herein again.
And when the second process monitors that the current value of the target marker bit is the target value, the first long connection is disconnected, and then the second process and the server establish a second long connection. The method for creating the long connection generally includes creating a socket (socket), communicating with the server through the socket, then monitoring whether a network port of the client receives response data from the server, if so, analyzing and processing the response data, and confirming that the long connection is successfully established. The method for creating a long connection is the prior art and is not described herein again.
And after the second process and the server establish a second long connection, receiving the message pushed by the server through the second long connection.
The process of establishing the long connection with the server in the client is transparent to the server, that is, the server does not know what process the process of establishing the long connection with the server is. The server includes the identification of the target process for executing the message in the message pushed to the client through the long connection. Taking the second long connection as an example, when the second process receives the message pushed by the server through the second long connection, the second process obtains the identifier of the target process in the message, and sends the message to the target process through the IPC.
In the embodiment, when the first long connection between the client and the server is detected to be disconnected, the second long connection is established with the server, so that at least one long connection is maintained between the client and the server, the real-time performance of data is guaranteed, and the reliability of a push channel is improved.
Optionally, in this embodiment, after the second process and the second long link with the server are established, a heartbeat data packet is further periodically sent to the server, where the heartbeat data packet includes an identifier of the client. For example, the client is identified by a Globally Unique Identifier (Globally called globalley Unique Identifier, GUID). Specifically, the heartbeat data packet may further include basic information such as a version and a number of bits of a current operating system of the client, which is not limited herein.
And when the second process receives a response data packet to the heartbeat data packet sent by the server, determining that the state of the second long connection is normal. Specifically, the response packet includes a special field, so that the client determines that the packet is a response to the heartbeat packet when receiving the response packet. Of course, when the first long connection is not disconnected, the first process may also monitor the state of the first long connection by using the method, and when the first process does not receive a response packet sent by the server after sending the heartbeat packet, it may be determined that the first long connection is disconnected.
In the embodiment shown in fig. 1, the second process is to establish the second long connection with the server only when the disconnection of the first long connection is detected. Optionally, in the present invention, when the first long connection is not disconnected, the second process may also establish a second long connection with the server.
In some possible implementations of the present invention, when the first long connection is not disconnected, the second process determines a preset value, where the preset value is used to indicate an upper limit of the number of long connections that can exist at the same time at the client, and the preset value may be set in the client by default or may be stored in the client by receiving a setting of a user, which is not limited herein. And when the preset value is greater than or equal to 2, the second process establishes the second long connection with the server.
In the present invention, the first process and the second process may be the same process. However, in the event of a disconnection of the first long connection, the path between the first process and the server is generally problematic, so it is preferred to replace one process with the server to establish a long connection, i.e. the first process and the second process are different processes. Or the first process and the second process are the same process, wherein when the second process detects that the first long connection is disconnected, the second process waits for a preset time length and then establishes a second long connection with the server.
The method of network communication of the present invention is described above from the client side, and the method of pushing messages of the present invention is described below from the server side.
Referring to fig. 2, fig. 2 is a flowchart illustrating a method for pushing a message according to an embodiment of the present invention. In this embodiment, the method for pushing a message includes:
201. when the first long connection established with the client is disconnected and an establishment request sent by the client is received, establishing a second long connection with the client.
202. And pushing a message to the client through the second long connection.
A first long connection is established between the server and the client. When the first long connection is disconnected, the client requests the server to establish a second long connection. When the server receives the establishment request, a second long connection is established with the client. And when the message needs to be pushed to the client, the message is sent through the second long connection.
In this embodiment, when the first long connection is disconnected, the server and the client establish a second long connection, so that at least one long connection is maintained between the client and the server, thereby ensuring real-time performance of data and improving reliability of a push path.
Optionally, in this embodiment, when the first long connection is not disconnected, if an establishment request sent by a client is received, a second long connection is established with the client. Thus, two long connections are established between the server and the client. When the server pushes the message to the client, one of the long connections can be selected to push the message, or the two long connections are alternately adopted to push the message.
Optionally, in this embodiment, in a case that two long connections are established between the server and the client, when the server pushes a message to the client, the server obtains loads of the first long connection and the second long connection; and pushing a message to the client by adopting the long connection with the smaller load in the first long connection and the second long connection. Among them, there are various methods of acquiring a load of a long connection. For example, the load of a long connection is confirmed by obtaining its current traffic. Of course, the above is merely exemplary and not limiting.
Optionally, in this embodiment, the server includes two modules, a state service and a logic service, where the state service is used to maintain a long connection between the server and each client, and the logic service is used to extract state information of the long connection from the state service and push a message to the client according to the state information. Specifically, the state service in the server periodically receives a heartbeat data packet sent by the client, and when the server receives the heartbeat data packet, the long connection state between the server and the client is normal, and returns a response data packet to the client, so that the client confirms that the long connection state is normal according to the response data packet. If the long connection state is normal, the server pushes the message to the client through the long connection when executing the message pushing.
For understanding the present invention, the following describes an example of the network communication method and the message pushing method according to the present invention with reference to a practical application scenario. Fig. 3 is a schematic structural diagram of an embodiment of a push message infrastructure according to the present invention.
In this embodiment, the client 30 includes a first process and a second process, and the first process and the second process may communicate through IPC, where the first process is a system service and the second process is a desktop application. The server 40 includes a status service module and a logic service module.
A first process within client 30, upon initiation, creates a socket through which to communicate with server 40, determines, upon listening to the receipt at the network port of response data from server 40, to establish a first long connection with server 40, and receives, via the second long connection, the message pushed by server 40. The first process also creates a target flag bit, and sets the value of the target flag bit to TRUE.
The second process and the first process in the client 30 monitor the current value of the target flag bit through IPC, and when the second process determines that the value of the target flag bit is TRUE, it is determined that the first long connection normally operates.
Within the working duration of the first long connection, the first process sends heartbeat packets to the state service module in the server 40 at preset time intervals, where the heartbeat packets include the identifier of the client 30. When the status service module in the server 40 receives the heartbeat packet, it confirms that the long connection status with the client 30 is normal, and returns a response packet to the client. The first process determines that the first long connection state is normal when receiving the response packet. And when the first process does not receive the response data packet of the heartbeat data packet, determining that the first long connection is disconnected, and changing the value of the marking bit into FALSE.
When the second process confirms that the value of the target flag bit is FALSE, a socket is created, the second process communicates with the server 40 through the socket, when it is monitored that the network port receives response data from the server 40, it is determined that a second long connection is established with the server 40, and a message pushed by the server 40 is received through the second long connection. Alternatively, in some special cases, the second process needs to establish a second long connection with the server 40, and the second process actively establishes the second long connection with the server 40, so that there are at least two long connections established with the server in the client 30 at the same time. Optionally, before establishing the second long connection with the server 40, the second process further obtains a preset value, where the preset value is used to indicate an upper limit of the number of long connections that can exist at the same time at the client; and when the preset value is greater than or equal to 2, establishing the second long connection with the server.
Within the working duration of the second long connection, the second process sends heartbeat packets to the state service module in the server 40 at preset time intervals, where the heartbeat packets include the identifier of the client 30. When the status service module in the server 40 receives the heartbeat packet, it confirms that the long connection status with the client 30 is normal, and returns a response packet to the client. And the second process determines that the second long connection state is normal when receiving the response data packet. And when the second process does not receive the response data packet of the heartbeat data packet, determining that the second long connection is disconnected.
The logical service module within the server 40 periodically retrieves the status information of the long connection with the client 30 from the status service module. If the long connection state is normal, the logic service module pushes a message to the client 30 according to a specific rule. When at least two long connections exist between the server 40 and the client 30, the logic service module may further obtain the status information of each long connection from the status service module, and if the status of each long connection is normal, the logic service module obtains the load of each long connection, and selects one long connection with the smallest load to push a message to the client 30 according to a specific rule.
Wherein the server 40 also includes an indication of the target process for processing the message in the message pushed to the client 30. A process within the client 30 that receives a message over a long connection sends the message to the target process through IPC based on the message so that the target process processes the message.
The network communication method and the message pushing method of the present invention are described above, and the network communication apparatus and the message pushing apparatus of the present invention will be described below.
Referring to fig. 4, fig. 4 is a schematic structural diagram of a network communication device according to an embodiment of the present invention. In this embodiment, the network communication apparatus 400 includes:
a detection module 401, configured to detect whether a first long connection is established with a server;
a monitoring module 402, configured to monitor a state of a first long connection when it is detected that the first long connection is established with a server;
an establishing module 403, configured to establish a second long link with the server when it is monitored that the first long connection is disconnected.
In the embodiment, when the first long connection between the client and the server is detected to be disconnected, the second long connection is established with the server, so that at least one long connection is maintained between the client and the server, the real-time performance of data is guaranteed, and the reliability of a push channel is improved.
Optionally, the network communication apparatus 400 further includes:
a communication module 404, configured to receive a message pushed by the server through the second long connection after the establishing module 403 establishes the second long connection with the server, where the message includes an indication of a target process for processing the message; and sending the message to the target process through inter-process communication IPC.
Optionally, the monitoring module 402 is specifically configured to monitor a value of a target marker bit when it is monitored that the first long connection is disconnected, where the value of the target marker bit is changed to a target value when the first long connection is disconnected; and when the current value of the target marker bit is monitored to be the target value, confirming that the first long connection is disconnected.
Optionally, the first long connection is a long connection established between a system service in the network communication device and the server;
and/or the presence of a gas in the gas,
the second long connection is a long connection established between the desktop application and the server in the network communication.
Optionally, the network communication apparatus 400 further includes:
a maintenance module 405, configured to periodically send a heartbeat data packet to the server after the establishing module establishes the second long link with the server, where the heartbeat data packet includes an identifier of the network communication; and when a response data packet to the heartbeat data packet sent by the server is received, determining that the state of the second long connection is normal.
Optionally, the establishing module 403 is further configured to:
determining a preset value when the first long connection is not disconnected, wherein the preset value is used for indicating an upper limit of the number of long connections which can exist simultaneously in the network communication;
and when the preset value is greater than or equal to 2, establishing the second long connection with the server.
Referring to fig. 5, fig. 5 is a schematic structural diagram of a message pushing device according to an embodiment of the present invention. In this embodiment, the apparatus 500 for pushing a message includes:
an establishing module 501, configured to establish a second long connection with a client when a first long connection established with the client is disconnected and an establishing request sent by the client is received;
a pushing module 502, configured to push a message to the client through the second long connection.
In this embodiment, when the first long connection is disconnected, the message pushing device and the client establish a second long connection, so that at least one long connection is maintained between the client and the message pushing device, thereby ensuring real-time performance of data and improving reliability of a push path.
Optionally, the establishing module 501 is further configured to, when the first long connection is not disconnected, if an establishing request sent by a client is received, establish a second long connection with the client.
Optionally, the pushing module 502 is configured to:
obtaining the loads of the first long connection and the second long connection;
and pushing a message to the client by adopting the long connection with the smaller load in the first long connection and the second long connection.
As shown in fig. 6, for convenience of description, only the parts related to the embodiment of the present invention are shown, and details of the specific technology are not disclosed, please refer to the method part of the embodiment of the present invention. The terminal may be any terminal device including a mobile phone, a tablet computer, a PDA (Personal digital assistant), a POS (Point of Sales), a vehicle-mounted computer, etc., taking the terminal as the mobile phone as an example:
fig. 6 is a block diagram illustrating a partial structure of a mobile phone related to a terminal provided in an embodiment of the present invention. Referring to fig. 6, the handset includes: radio Frequency (RF) circuit 1010, memory 1020, input unit 1030, display unit 1040, sensor 1050, audio circuit 1060, wireless fidelity (WiFi) module 1070, processor 1080, and power source 1090. Those skilled in the art will appreciate that the handset configuration shown in fig. 6 is not intended to be limiting and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components.
The following describes each component of the mobile phone in detail with reference to fig. 6:
The memory 1020 can be used for storing software programs and modules, and the processor 1080 executes various functional applications and data processing of the mobile phone by operating the software programs and modules stored in the memory 1020. The memory 1020 may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required by at least one function (such as a sound playing function, an image playing function, etc.), and the like; the storage data area may store data (such as audio data, a phonebook, etc.) created according to the use of the cellular phone, and the like. Further, the memory 1020 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid state storage device.
The input unit 1030 may be used to receive input numeric or character information and generate key signal inputs related to user settings and function control of the cellular phone. Specifically, the input unit 1030 may include a touch panel 1031 and other input devices 1032. The touch panel 1031, also referred to as a touch screen, may collect touch operations by a user (e.g., operations by a user on or near the touch panel 1031 using any suitable object or accessory such as a finger, a stylus, etc.) and drive corresponding connection devices according to a preset program. Alternatively, the touch panel 1031 may include two parts, a touch detection device and a touch controller. The touch detection device detects the touch direction of a user, detects a signal brought by touch operation and transmits the signal to the touch controller; the touch controller receives touch information from the touch sensing device, converts the touch information into touch point coordinates, sends the touch point coordinates to the processor 1080, and can receive and execute commands sent by the processor 1080. In addition, the touch panel 1031 may be implemented by various types such as a resistive type, a capacitive type, an infrared ray, and a surface acoustic wave. The input unit 1030 may include other input devices 1032 in addition to the touch panel 1031. In particular, other input devices 1032 may include, but are not limited to, one or more of a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a track ball, a mouse, a joystick, or the like.
The display unit 1040 may be used to display information input by a user or information provided to the user and various menus of the cellular phone. The Display unit 1040 may include a Display panel 1041, and optionally, the Display panel 1041 may be configured in the form of a Liquid Crystal Display (LCD), an Organic Light-Emitting Diode (OLED), or the like. Further, the touch panel 1031 can cover the display panel 1041, and when the touch panel 1031 detects a touch operation on or near the touch panel 1031, the touch operation is transmitted to the processor 1080 to determine the type of the touch event, and then the processor 1080 provides a corresponding visual output on the display panel 1041 according to the type of the touch event. Although in fig. 6, the touch panel 1031 and the display panel 1041 are two independent components to implement the input and output functions of the mobile phone, in some embodiments, the touch panel 1031 and the display panel 1041 may be integrated to implement the input and output functions of the mobile phone.
The handset may also include at least one sensor 1050, such as a light sensor, motion sensor, and other sensors. Specifically, the light sensor may include an ambient light sensor and a proximity sensor, wherein the ambient light sensor may adjust the brightness of the display panel 1041 according to the brightness of ambient light, and the proximity sensor may turn off the display panel 1041 and/or the backlight when the mobile phone moves to the ear. As one of the motion sensors, the accelerometer sensor can detect the magnitude of acceleration in each direction (generally, three axes), can detect the magnitude and direction of gravity when stationary, and can be used for applications of recognizing the posture of a mobile phone (such as horizontal and vertical screen switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer and tapping), and the like; as for other sensors such as a gyroscope, a barometer, a hygrometer, a thermometer, and an infrared sensor, which can be configured on the mobile phone, further description is omitted here.
WiFi belongs to short-distance wireless transmission technology, and the mobile phone can help the user to send and receive e-mail, browse web pages, access streaming media, etc. through the WiFi module 1070, which provides wireless broadband internet access for the user. Although fig. 6 shows the WiFi module 1070, it is understood that it does not belong to the essential constitution of the handset, and can be omitted entirely as needed within the scope not changing the essence of the invention.
The processor 1080 is a control center of the mobile phone, connects various parts of the whole mobile phone by using various interfaces and lines, and executes various functions of the mobile phone and processes data by operating or executing software programs and/or modules stored in the memory 1020 and calling data stored in the memory 1020, thereby integrally monitoring the mobile phone. Optionally, processor 1080 may include one or more processing units; preferably, the processor 1080 may integrate an application processor, which handles primarily the operating system, user interfaces, applications, etc., and a modem processor, which handles primarily the wireless communications. It is to be appreciated that the modem processor described above may not be integrated into processor 1080.
The handset also includes a power source 1090 (e.g., a battery) for powering the various components, which may preferably be logically coupled to the processor 1080 via a power management system to manage charging, discharging, and power consumption via the power management system.
Although not shown, the mobile phone may further include a camera, a bluetooth module, etc., which are not described herein.
In the embodiment of the present invention, the processor 1080 included in the terminal further has a function of controlling the above method flow executed by the network communication device or the client.
Fig. 7 is a schematic diagram of a server 1100 according to an embodiment of the present invention, where the server 1100 may have a relatively large difference due to different configurations or performances, and may include one or more Central Processing Units (CPUs) 1122 (e.g., one or more processors) and a memory 1132, and one or more storage media 1130 (e.g., one or more mass storage devices) for storing applications 1142 or data 1144. Memory 1132 and storage media 1130 may be, among other things, transient storage or persistent storage. The program stored on the storage medium 1130 may include one or more modules (not shown), each of which may include a series of instruction operations for the server. Still further, the central processor 1122 may be provided in communication with the storage medium 1130 to execute a series of instruction operations in the storage medium 1130 on the server 1100.
The server 1100 may also include one or more power supplies 1126, one or more wired or wireless network interfaces 1150, one or more input-output interfaces 1158, and/or one or more operating systems 1141, such as Windows Server, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, and so forth.
The steps performed by the server or the device pushing messages in the above embodiments may be based on the server structure shown in fig. 7.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the several embodiments provided in the present application, it should be understood that the disclosed system, apparatus and method may be implemented in other manners. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The above-mentioned embodiments are only used for illustrating the technical solutions of the present invention, and not for limiting the same; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.
Claims (17)
1. A method of network communication, comprising:
detecting whether a first long connection is established between the server and the server;
when detecting that a first long connection is established between the server and the server, monitoring the state of the first long connection;
when the first long connection is monitored to be disconnected, establishing a second long connection with the server;
when the first long connection is not disconnected and the preset value is greater than or equal to 2, establishing a second long connection with the server; the preset value is used for indicating the upper limit of the number of long connections which can exist at the same time by the client; the first long connection and the second long connection are used for alternatively or alternatively receiving the push message of the server.
2. The method of network communication according to claim 1, wherein said establishing a second long connection with said server further comprises:
receiving a message pushed by the server through the second long connection, wherein a target process for processing the message is also indicated in the message;
and sending the message to the target process through inter-process communication IPC.
3. The method of network communication according to claim 1, wherein when the first long connection disconnection is monitored, the method comprises:
monitoring a value of a target marker bit, wherein the value of the target marker bit is changed to a target value when the first long connection is disconnected;
and when the current value of the target marker bit is monitored to be the target value, confirming that the first long connection is disconnected.
4. The method of network communication according to claim 1, wherein the first long connection is a long connection established between a system service in a client and the server;
and/or the presence of a gas in the gas,
the second long connection is a long connection established between the desktop application in the client and the server.
5. The method of network communication according to claim 1, wherein said establishing a second long connection with said server further comprises:
periodically sending heartbeat data packets to a server, wherein the heartbeat data packets comprise the identification of a client;
and when a response data packet to the heartbeat data packet sent by the server is received, determining that the state of the second long connection is normal.
6. A method for pushing a message, comprising:
when a first long connection established with a client is disconnected and an establishment request sent by the client is received, establishing a second long connection with the client;
pushing a message to the client through the second long connection;
when the first long connection is not disconnected, if a building request sent by a client is received, building a second long connection with the client; the first long connection and the second long connection are used for alternatively or alternately pushing messages to the client.
7. The method of pushing a message according to claim 6, further comprising:
obtaining the loads of the first long connection and the second long connection;
and pushing a message to the client by adopting the long connection with the smaller load in the first long connection and the second long connection.
8. An apparatus for network communication, comprising:
the detection module is used for detecting whether a first long connection is established between the detection module and the server;
the monitoring module is used for monitoring the state of a first long connection when the first long connection with the server is established;
the establishing module is used for establishing a second long connection with the server when the first long connection is monitored to be disconnected;
the establishing module is further configured to determine a preset value when the first long connection is not disconnected, where the preset value is used to indicate an upper limit of the number of long connections where the network communication may exist simultaneously; when the preset value is greater than or equal to 2, establishing the second long connection with the server; the first long connection and the second long connection are used for alternatively or alternatively receiving the push message of the server.
9. The apparatus for network communication according to claim 8, wherein the apparatus further comprises:
the communication module is used for receiving a message pushed by the server through the second long connection after the establishment module establishes the second long connection with the server, and a target process used for processing the message is also indicated in the message; and sending the message to the target process through inter-process communication IPC.
10. The device according to claim 8, wherein the monitoring module is specifically configured to monitor a value of a target flag bit when it is monitored that the first long connection is disconnected, where the value of the target flag bit is changed to a target value when the first long connection is disconnected; and when the current value of the target marker bit is monitored to be the target value, confirming that the first long connection is disconnected.
11. The apparatus for network communication according to claim 8, wherein the first long connection is a long connection established between a system service in the apparatus for network communication and the server;
and/or the presence of a gas in the gas,
the second long connection is a long connection established between a desktop application in the network communication device and the server.
12. The apparatus for network communication according to claim 8, wherein the apparatus further comprises:
a maintenance module, configured to periodically send a heartbeat packet to the server after the establishing module establishes the second long connection with the server, where the heartbeat packet includes an identifier of the network communication device; and when a response data packet to the heartbeat data packet sent by the server is received, determining that the state of the second long connection is normal.
13. An apparatus for pushing a message, comprising:
the system comprises an establishing module, a sending module and a receiving module, wherein the establishing module is used for establishing a first long connection with a client and establishing a second long connection with the client when the first long connection established with the client is disconnected and an establishing request sent by the client is received;
the pushing module is used for pushing a message to the client through the second long connection;
the establishing module is further used for establishing a second long connection with the client if an establishing request sent by the client is received when the first long connection is not disconnected; the first long connection and the second long connection are used for alternatively or alternately pushing messages to the client.
14. The apparatus for pushing a message according to claim 13, wherein the pushing module is configured to:
obtaining the loads of the first long connection and the second long connection;
and pushing a message to the client by adopting the long connection with the smaller load in the first long connection and the second long connection.
15. A terminal device comprising a memory and a processor;
the memory is used for storing a software program;
the processor is configured to run the software program to perform the method of network communication according to any one of claims 1-5.
16. A server, comprising a memory and a processor;
the memory is used for storing a software program;
the processor is configured to run the software program to perform the method of pushing messages according to any one of claims 6-7.
17. A computer-readable storage medium having stored therein instructions for causing a computer device to perform the method of network communication of any one of claims 1-5 or the method of pushing messages of any one of claims 6-7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610807978.8A CN107800585B (en) | 2016-09-07 | 2016-09-07 | Network communication method and device, and message pushing method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610807978.8A CN107800585B (en) | 2016-09-07 | 2016-09-07 | Network communication method and device, and message pushing method and device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN107800585A CN107800585A (en) | 2018-03-13 |
CN107800585B true CN107800585B (en) | 2021-01-12 |
Family
ID=61530854
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201610807978.8A Active CN107800585B (en) | 2016-09-07 | 2016-09-07 | Network communication method and device, and message pushing method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN107800585B (en) |
Families Citing this family (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN109600444A (en) * | 2018-12-14 | 2019-04-09 | 北京向上心科技有限公司 | Data push method, server, terminal, electronic equipment and readable storage medium storing program for executing |
CN110958162A (en) * | 2019-12-06 | 2020-04-03 | 广东博智林机器人有限公司 | BLE cascade network, link detection method, equipment and terminal thereof |
CN113162956A (en) * | 2020-01-22 | 2021-07-23 | 华为技术有限公司 | Method, device and network equipment for establishing communication connection |
CN111726413B (en) * | 2020-06-28 | 2022-05-17 | 北京百度网讯科技有限公司 | Equipment connection method and device |
CN112437329B (en) * | 2020-11-05 | 2024-01-26 | 上海幻电信息科技有限公司 | Method, device and equipment for playing video and readable storage medium |
CN115297162B (en) * | 2022-06-27 | 2024-03-22 | 青岛海尔科技有限公司 | Message sending method and device, storage medium and electronic device |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103532943A (en) * | 2013-10-08 | 2014-01-22 | 北京神州绿盟信息安全科技股份有限公司 | Web application firewall device and asynchronous security protection log processing method |
CN103916936A (en) * | 2013-01-04 | 2014-07-09 | ***通信集团公司 | Method and system for realizing data long connection, mobile terminal and server |
CN104717133A (en) * | 2015-03-16 | 2015-06-17 | 墨仕(厦门)电子商务有限公司 | Distributed message push system and method |
CN105677451A (en) * | 2014-11-18 | 2016-06-15 | 北京风行在线技术有限公司 | Load balancing method and equipment used for multiple processes |
Family Cites Families (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102291808B (en) * | 2011-06-03 | 2013-12-04 | 莫雅静 | Network communication method, communication equipment and middleware of communication equipment |
CN103024043B (en) * | 2012-12-14 | 2016-01-27 | 腾讯科技(深圳)有限公司 | A kind of data sharing method, server and system |
CN103605689B (en) * | 2013-11-01 | 2017-12-29 | 北京奇虎科技有限公司 | It is a kind of to obtain the method and device for accessing the residence time |
CN103944923A (en) * | 2014-05-14 | 2014-07-23 | 沈文策 | Network information processing system and method |
CN105357283B (en) * | 2015-10-20 | 2020-02-11 | 北京奇宝科技有限公司 | Long connection establishing method of intelligent wearable equipment, server and terminal |
CN105681391A (en) * | 2015-12-28 | 2016-06-15 | 智慧方舟科技有限公司 | Server, Android client and network communication method and device of server and Android client |
-
2016
- 2016-09-07 CN CN201610807978.8A patent/CN107800585B/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103916936A (en) * | 2013-01-04 | 2014-07-09 | ***通信集团公司 | Method and system for realizing data long connection, mobile terminal and server |
CN103532943A (en) * | 2013-10-08 | 2014-01-22 | 北京神州绿盟信息安全科技股份有限公司 | Web application firewall device and asynchronous security protection log processing method |
CN105677451A (en) * | 2014-11-18 | 2016-06-15 | 北京风行在线技术有限公司 | Load balancing method and equipment used for multiple processes |
CN104717133A (en) * | 2015-03-16 | 2015-06-17 | 墨仕(厦门)电子商务有限公司 | Distributed message push system and method |
Also Published As
Publication number | Publication date |
---|---|
CN107800585A (en) | 2018-03-13 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN107800585B (en) | Network communication method and device, and message pushing method and device | |
KR101978590B1 (en) | Message updating method, device and terminal | |
CN108255683B (en) | Method for prompting message in terminal and terminal | |
CN110620822A (en) | Network element determination method and device | |
CN110856103B (en) | Scheduling method, communication method and related equipment | |
CN106293738B (en) | Expression image updating method and device | |
CN106230703A (en) | The process of chat record and acquisition methods and device | |
CN106101764A (en) | A kind of methods, devices and systems showing video data | |
CN105227598B (en) | Resource sharing method, device and system based on cloud storage | |
CN112691363A (en) | Cross-terminal switching method and related device for cloud games | |
CN110662277A (en) | Power saving management method, graphical user interface and terminal | |
CN109495769B (en) | Video communication method, terminal, smart television, server and storage medium | |
CN115242805A (en) | Gossip-based distributed MQTT message transmission method, transmission system and storage medium | |
CN107317828B (en) | File downloading method and device | |
CN106470234B (en) | Equipment discovery method and device | |
CN107770381B (en) | Network management method and related product | |
CN105577712B (en) | A kind of file uploading method, device and system | |
CN107104760B (en) | Method for transmitting data packet, client and server | |
CN105025064B (en) | Download the method, apparatus and system of file | |
CN114124924A (en) | Method, equipment and system for determining configuration information | |
CN107786423B (en) | A kind of method and system of instant messaging | |
CN110602766A (en) | Personal hotspot identification method and method for determining association relationship between terminals | |
CN106209601B (en) | State update message pushing method and device | |
CN107889128B (en) | Network quality adjusting method and device | |
CN106686704B (en) | Terminal monitoring method and mobile terminal |
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 | ||
TR01 | Transfer of patent right |
Effective date of registration: 20221130 Address after: 1402, Floor 14, Block A, Haina Baichuan Headquarters Building, No. 6, Baoxing Road, Haibin Community, Xin'an Street, Bao'an District, Shenzhen, Guangdong 518000 Patentee after: Shenzhen Yayue Technology Co.,Ltd. Address before: 2, 518000, East 403 room, SEG science and Technology Park, Zhenxing Road, Shenzhen, Guangdong, Futian District Patentee before: TENCENT TECHNOLOGY (SHENZHEN) Co.,Ltd. |
|
TR01 | Transfer of patent right |