Summary of the invention
Based on this, be necessary to need to expend server resource in a large number for the existing method realizing reverse push carry information, lack the defect of real-time, provide the method for the server push carry information that a kind of real-time is high, server resource consumption is few and client to receive the method for pushed information.
A method for server push carry information, comprising:
Receive the first packet that client is sent by udp protocol at interval of first Preset Time, described first packet carries client address information;
Judge whether to there is information to be pushed, if, then according to the first packet described client address information of carrying that the last time receives, send the 3rd packet by udp protocol to described client, the 3rd packet carries the information requiring client to send to set up TCP connection request;
Respond the request that described client initiates to set up TCP connection, set up TCP with described client and be connected, connected by TCP and send described information to be pushed to described client;
After completing and sending described information to be pushed to described client, disconnect and being connected with the TCP of described client.
In one embodiment, comprise after the step of the first packet that described reception client is sent by udp protocol at interval of first Preset Time:
Often receive described first packet, then accordingly send second packet for responding by udp protocol to described client;
In one embodiment, also comprise:
Judge described first packet whether receiving the transmission of described client in the second Preset Time, if not, then notify that described client regulates described first Preset Time.
In one embodiment, whether described judgement receives described first packet that described client sends in the second Preset Time, if not, then notifies that described client regulates the step of described first Preset Time specifically to comprise:
Judge described first packet whether receiving the transmission of described client in the second Preset Time, if not, then mark corresponding client, and be recorded as the first client;
After the next one first packet receiving described first client, send the 4th packet by udp protocol to described first client, described 4th packet carries and notifies that described client reduces the information of described first Preset Time.
Client receives a method for pushed information, comprising:
Send first packet by udp protocol to server at interval of first Preset Time, described first packet carries client address information;
Judge whether to get that described server sends carries the 3rd packet requiring to set up TCP connectivity request message, be, initiate to set up to described server the request that TCP connects;
Set up TCP with described server to be connected, connected by TCP and carry out the information to be pushed receiving described server;
Complete receive described server after PUSH message, disconnect be connected with the TCP of described server.
In one embodiment, describedly also to be comprised after server sends the step of the first packet by udp protocol at interval of first Preset Time:
Judge whether to receive the second packet for responding described first packet that described server is sent by udp protocol, continue to send first packet by udp protocol to described server at interval of first Preset Time, otherwise reduce described first Preset Time.
In one embodiment, also comprise:
Judge whether to receive the notice of described first Preset Time of adjustment that described server sends, the notice of described first Preset Time of adjustment if so, then sent according to described server regulates described first Preset Time.
In one embodiment, the described notice judging whether described first Preset Time of adjustment receiving the transmission of described server, the notice of described first Preset Time of adjustment if so, then sent according to described server regulates the step of described first Preset Time specifically to comprise:
Judge whether to receive the 4th packet that described server is sent by udp protocol, described 4th packet carries the information that notice reduces described first Preset Time, if so, then reduces described first Preset Time according to described 4th packet.
The method of above-mentioned Internet of Things server reverse push carry information and Internet of Things client receive the method for reverse push carry information, by UDP (UserDatagramProtocol, User Datagram Protoco (UDP)) client address information is sent to server by agreement, because UDP is a kind of connectionless, the transport layer protocol that reliability is poor, simple unreliable information transfer service towards affairs is provided, thus there is resource consumption little, the advantage that processing speed is fast, when server needs pushed information, the notice that there is information to be pushed is sent by UDP message bag, taking server resource is reduced with this, and improve the processing speed of client and server, thus save server cost, in addition, realize the real time communication of client and server, client is set up after receiving pushed information notice and is connected for sending PUSH message with the TCP of server, data transmission credibility is improved with this, and make information pushing have real-time.
Embodiment
For the ease of understanding the present invention, below with reference to relevant drawings, the present invention is described more fully.Preferred embodiment of the present invention is given in accompanying drawing.But the present invention can realize in many different forms, is not limited to embodiment described herein.On the contrary, provide the object of these embodiments be make the understanding of disclosure of the present invention more comprehensively thorough.
It is worth mentioning that, the present invention is particularly useful for various internet-of-things terminal, as mobile phone, panel computer or other mobile terminals, is only described in detail with the use scenes of mobile phone in the following embodiments.
As shown in Figure 1, a preferred embodiment of the method for a kind of server push carry information of the present invention, comprises the following steps:
Step S110, receive the first packet that client is sent by udp protocol at interval of first Preset Time, described first packet carries client address information.
Udp protocol is a kind of connectionless, the transport layer protocol that reliability is poor, simple unreliable information transfer service towards affairs is provided, do not belong to connecting-type agreement, thus there is resource consumption little, the advantage that processing speed is fast, like this, server by receive the first packet can Real-time Obtaining to the presence of each client and address information, maintain contacting of server and client, and server is without the need to consuming excess resource, thus server can be maintained with more client simultaneously contact, it should be understood that, described resource comprises server memory, CPU usage, R/W speed of hard disc and the network bandwidth etc., server resource uses too high, mean that the EMS memory occupation of server is large, CPU usage is high, R/W speed of hard disc is low, and network congestion, to the operating efficiency of server be caused to reduce like this.
Because each client has internal address all respectively, in order to process the address information of each client, server is after the address information receiving client transmission, described server sets up client address information MAP table to identify different clients, like this, when server needs with client communication, can fast finding client by mapping address information list server.Because the address of client may constantly change, therefore in order to obtain the address information of up-to-date client, client needs sending first packet at interval of first Preset Time, with the address information making server can get up-to-date client.
Step S120, judge whether to there is information to be pushed, if, the described client address information that the first packet then received according to the last time carries, send the 3rd packet by udp protocol to described client, the 3rd packet carries the information requiring client to send to set up TCP connection request.
When there is the information wait pushing in server, in other words, when server needs pushed information, then need to set up and be connected with the TCP of client, connected by TCP and send information to be pushed, because TCP connection must be initiated by client, TCP connection request can be initiated in time to allow client, server sends the 3rd packet carrying and ask to set up the information that TCP is connected with described client to client by udp protocol, such as, 3rd packet carries the notice requiring client to send to set up TCP connection request, such as, 3rd packet is for notifying client, there is pushed information to be pushed in server, require that client initiates to set up the request of TCP connection, on the one hand, when not setting up TCP and connecting, can notify that client initiates TCP connection request in time, pushed information is made to have real-time, on the other hand, take the little advantage of resource because udp protocol has, make server send the 3rd packet to multiple client simultaneously, take less server resource, thus improve the treatment effeciency of server.
Step S130, is responded the request that described client initiates to set up TCP connection, sets up TCP be connected with described client, connected send described information to be pushed to described client by TCP.
After client initiates TCP connection request, server and client are set up TCP and are connected, connected to client push information by TCP, due to TCP connect be a kind of connection-oriented, reliable, based on the transport layer communication protocol of byte stream, greatly can improve the reliability of pushed information, in one embodiment, also comprise and adopt SSL cryptographic protocol to be encrypted pushed information, connected by TCP after encryption and send described information to be pushed to described client, thus make information to be pushed can push to client safely and reliably.
Step S140, after completing and sending described information to be pushed to described client, disconnects and being connected with the TCP of described client.
Set up TCP when server and multiple client to be connected simultaneously, and when being connected to client push information by TCP, the resource of server will be consumed in a large number, cause the operating efficiency of server low, discharged to make server resource, improve the operating efficiency of server, complete after client push information, disconnect and being connected with the TCP of client, Resource recovery, when not pushed information, the resource of server is discharged, improves the operating efficiency of server with this.
By udp protocol, client address information is sent to server, because UDP is a kind of connectionless, the transport layer protocol that reliability is poor, thus there is resource consumption little, the advantage that processing speed is fast, when server needs pushed information, the notice that there is information to be pushed is sent by UDP message bag, taking server resource is reduced with this, and improve the processing speed of client and server, thus save server cost, in addition, realize the real time communication of client and server, client is set up after receiving pushed information notice and is connected for sending PUSH message with the TCP of server, data transmission credibility is improved with this, and make information pushing have real-time.
In one embodiment, comprise after step S110:
Step S111, often receives described first packet, then accordingly sends second packet for responding by udp protocol to described client.
Because udp protocol is a kind of connectionless, the transport layer protocol that reliability is poor, therefore, after client have sent the first packet, whether cannot receive the first packet by confirmed service device, the information of the first packet whether can be received by Real-time Obtaining server in order to make client, server is after often receiving first packet, then send the second packet by udp protocol to client, second packet is used for the first packet of customer in response end, notice client successfully receives corresponding upper first packet, improve the reliability of data packet transmission.
In one embodiment, the method for server push carry information of the present invention also comprises:
Step S112, judges described first packet whether receiving the transmission of described client in the second Preset Time, if not, then notifies that described client regulates described first Preset Time.
When server does not receive the first packet of client transmission in the second Preset Time, mean that the network of this client may break down, the real-time of the first packet is received in order to improve server, avoid client cannot receive the information setting up TCP connection of server due to address change, server notice client regulates the first Preset Time, such as, notify that the time interval of client to transmission first packet regulates.
It should be understood that, described first Preset Time is the transmission interval between the first packet of two order transmissions, described second Preset Time is the time interval for calculating the first packet not receiving client that server is preset, such as, described second Preset Time is according to client terminal quantity, first Preset Time, network condition or server resource situation regulate, such as, described second Preset Time is different from described first Preset Time, such as, described second Preset Time is greater than described first Preset Time, like this, after repeatedly not receiving the first packet, server notice client regulates the first Preset Time, such as, described second Preset Time equals described first Preset Time, then server does not receive the first packet in the first Preset Time, then notify that client regulates the first Preset Time, i.e. each first packet of client transmission, then this first packet of the corresponding reception of server, once server does not receive the first packet, then notify that client regulates the first Preset Time, to improve the acceptance rate of the first packet.
In one embodiment, step S102, specifically comprises:
Step S113, judges described first packet whether receiving the transmission of described client in the second Preset Time, if not, then marks corresponding client, and be recorded as the first client.
Because server receives the first packet of multiple client simultaneously, the network condition of each client is not identical, and server marks the client for receiving the first packet, for distinguishing the client of packet loss and the normal client sent.
Step S114, after the next one first packet receiving described first client, sends the 4th packet by udp protocol to described first client, and described 4th packet carries and notifies that described client reduces the information of described first Preset Time.
More accurate in order to make server regulate the notice of the first Preset Time to send to client, need to confirm the address of the client of packet loss further, server receives next first packet after packet loss, the address information of then carrying according to this first packet sends the 4th packet, to notify that the first client reduces the first Preset Time to the first client of correspondence.Reduce the first Preset Time and mean that client sends the time interval shortening of the first packet, like this, the client that there is packet drop will send more first packet within the unit interval, make server within the unit interval, receive more first packet of packet loss client as much as possible, improve with this real-time that client sends the first packet, reduce the impact that packet loss brings.
In one embodiment, method further comprising the steps of of server push carry information of the present invention:
Judge whether the data volume of information to be pushed is less than preset data amount, is, sends described information to be pushed by udp protocol.When information to be pushed data volume is less, carries out transmission information to be pushed without the need to being connected by TCP, directly sending information to be pushed by udp protocol, reduce the consumption to server resource further.
As shown in Figure 2, the present invention also provides a kind of client to receive the method for pushed information, comprises the following steps:
Step S210, sends first packet by udp protocol to server at interval of first Preset Time, and described first packet carries client address information.
Real-time address information is sent to server by udp protocol by client, to maintain and the contacting of server, makes server can get the real-time address information of each client, is convenient to send notice to client.
Step S220, judges whether to get that described server sends carries the 3rd packet requiring to set up TCP connectivity request message, is, initiates to set up to described server the request that TCP connects.
When there is information to be pushed in server, server sends the 3rd packet to client, described 3rd packet carries requirement and sets up TCP connectivity request message, such as, described 3rd packet is for notifying that client exists information to be pushed, and such as, described 3rd packet carries the notice that server exists information to be pushed, what receive server when client comprises after this notifies the 3rd packet, then initiate to set up to server the request that TCP connects.
Step S230, sets up TCP with described server and is connected, and is connected carry out the information to be pushed receiving described server by TCP.
After server has responded TCP connection request, client has connected to come the information to be pushed of reception server by TCP.
Step S240, complete receive described server after PUSH message, disconnect be connected with the TCP of described server.
Client reception server after PUSH message, in order to reduce taking server resource, disconnect be connected with the TCP of server, make the TCP of server connection shared by resource be released.
In one embodiment, also comprise after step S210:
Step S211, judge whether to receive the second packet for responding described first packet that described server is sent by udp protocol, continue to send first packet by udp protocol to described server at interval of first Preset Time, otherwise reduce described first Preset Time.
Because server is after often receiving first packet, by feedback second packet to client, represent that server successfully receives the first packet, then now client continues to send the first packet to server at interval of first Preset Time, if client does not receive the second packet that server sends, then show that the first packet of client transmission before this does not send successfully or server does not receive successfully, then client needs the interval adjusting transmission first packet, to improve the real-time of the first packet.
In one embodiment, the method for client reception pushed information of the present invention also comprises:
Step S212, judges whether to receive the notice of described first Preset Time of adjustment that described server sends, and the notice of described first Preset Time of adjustment if so, then sent according to described server regulates described first Preset Time.
If client receives the notice of adjustment first Preset Time that server sends, then show that server does not receive the first packet, there is the phenomenon of packet loss in the first packet that client sends, then client regulates described first Preset Time, to improve the acceptance rate of the first packet according to this notice.
In one embodiment, step S202 specifically comprises:
Step S213, judges whether to receive the 4th packet that described server is sent by udp protocol, and described 4th packet carries the information that notice reduces described first Preset Time, if so, then reduces described first Preset Time according to described 4th packet.
If client receives the 4th packet of server, then reduce the first Preset Time according to the 4th packet, namely the time interval of transmission first packet is reduced, make the client that there is packet loss phenomenon within the unit interval, send more first packet, make server within the unit interval, receive more first packet of packet loss client as much as possible, improve with this real-time that client sends the first packet, reduce the impact that packet loss brings.
Should be noted that in said system embodiment, included modules is carry out dividing according to function logic, but is not limited to above-mentioned division, as long as can realize corresponding function; In addition, the concrete title of each functional unit, also just for the ease of mutual differentiation, is not limited to protection scope of the present invention.
In addition, one of ordinary skill in the art will appreciate that all or part of step realized in the various embodiments described above method is that the hardware that can carry out instruction relevant by program has come, corresponding program can be stored in read/write memory medium.
Each technical characteristic of the above embodiment can combine arbitrarily, for making description succinct, the all possible combination of each technical characteristic in above-described embodiment is not all described, but, as long as the combination of these technical characteristics does not exist contradiction, be all considered to be the scope that this specification is recorded.
The above embodiment only have expressed several execution mode of the present invention, and it describes comparatively concrete and detailed, but can not therefore be construed as limiting the scope of the patent.It should be pointed out that for the person of ordinary skill of the art, without departing from the inventive concept of the premise, can also make some distortion and improvement, these all belong to protection scope of the present invention.Therefore, the protection range of patent of the present invention should be as the criterion with claims.