Summary of the invention
In view of this, main purpose of the present invention is to provide a kind of instant communication method, can saving network flow.
Another object of the present invention is to provide a kind of instant communicating system, can saving network flow.
Another object of the present invention is to provide a kind of client, can saving network flow.
Another object of the present invention is to provide a kind of Relay Server, can saving network flow.
For achieving the above object, technical scheme of the present invention is achieved in that
A kind of instant communication method, comprising:
After user utilizes a client X to log in, described client X sets up and is connected with the length between Relay Server;
When user writes data at every turn, described client X sets up and is connected with short between operations server, and the data of write is passed through set up short connection and send to described operations server; Described operations server is set up and is connected with short between described Relay Server, and the data of write is passed through set up short connection and send to described Relay Server; The data separate of write self is sent to described instant communication server with long connection of setting up between instant communication server by described Relay Server;
After receiving described instant communication server and returning to the data of described client X, described Relay Server utilizes long connection of setting up between self with described client X that the data returned are sent to described client X.
A kind of instant communicating system, comprising: client, Relay Server, operations server and instant communication server; Wherein, the number of described client is more than one;
Each client X, is respectively used to after user utilizes and self logs in, and sets up and is connected with long between described Relay Server; When user writes data at every turn, set up and be connected with short between described operations server, the data of write are passed through set up short connection and send to described operations server, and by receiving with long connection of setting up between described Relay Server the data that described instant communication server that described Relay Server sends returns to self;
Described operations server, for when after the data receiving write, sets up and is connected with short between described Relay Server, and the data of write is passed through set up short connection and send to described Relay Server;
Described Relay Server, for the data separate of write self is sent to described instant communication server with long connection of setting up between described instant communication server, and after receiving described instant communication server and returning to the data of described client X, utilize long connection of setting up between self with described client X that the data returned are sent to described client X.
A kind of client, comprising: the first processing unit and the second processing unit;
Described first processing unit, after utilizing as user and self logging in, sets up and is connected with long between Relay Server;
Described second processing unit, for when user writes data at every turn, sets up and is connected with short between operations server, and the data of write is passed through set up short connection and send to described operations server;
Described first processing unit is further used for, and receives by described long connection the data that instant communication server that described Relay Server sends returns to self.
A kind of Relay Server, comprising: the 3rd processing unit and fourth processing unit;
Described 3rd processing unit, for the short data being connected user's write that the described operations server of reception is sent by setting up between self with operations server, the data separate of write self is sent to described instant communication server with long connection of setting up between instant communication server;
Described fourth processing unit, for after receiving described instant communication server and returning to the data of any client, utilizes long connection of setting up between self with described client that the data returned are sent to described client.
Visible, adopt technical scheme of the present invention, client by obtaining with long connection of setting up between Relay Server the data that instant communication server returns to self, thus avoids and sets up useless short connection one after another, and then saves network traffics.
Embodiment
For problems of the prior art, the instant messaging scheme after a kind of improvement is proposed in the present invention, can saving network flow.
For make technical scheme of the present invention clearly, understand, to develop simultaneously embodiment referring to accompanying drawing, scheme of the present invention be described in further detail.
The flow chart of Fig. 1 instant communication method embodiment of the present invention.As shown in Figure 1, comprise the following steps:
Step 11: after user utilizes a client X to log in, client X sets up and is connected with the length between Relay Server.
In the present embodiment, adopt the mode of HTML (Hypertext Markup Language) (HTTP, HyperText Transfer Protocol) long connecting analog socket communication.
Fig. 2 is that client X of the present invention sets up and the long process schematic be connected between Relay Server.As shown in Figure 2, comprising:
Step 201: client X sends link order to Relay Server.
Step 202: Relay Server returns welcome message to client X.
Described welcome message can be <script>hello (); </script>.
So far, connection establishment.
Step 12: when user writes data at every turn, client X sets up and is connected with short between operations server, and the data of write is passed through set up short connection and send to operations server; Operations server is set up and is connected with short between Relay Server, and the data of write is passed through set up short connection and send to Relay Server.
In the present embodiment, the read-write operation of user is separated, and the corresponding server disposing difference in functionality, i.e. operations server and Relay Server.
When user writes data at every turn, to set up between operations server short is connected for client X, by this short connection, the data of write sent to operations server; Operations server simply unpacks process to it after receiving the data of write, and sets up and be connected with short between Relay Server, and the data after unpacking are sent to Relay Server.
Step 13: the data separate of write self is sent to instant communication server with long connection of setting up between instant communication server by Relay Server.
Fig. 3 is that Relay Server of the present invention is set up and the long process schematic be connected between instant communication server.As shown in Figure 3, comprising:
Step 301: Relay Server sends link order to instant communication server.
Step 302: instant communication server returns welcome message to Relay Server.
Described welcome message can be OK.
So far, connection establishment.
After data after what Relay Server received that operations server sends unpack, package again can be carried out to it, namely be encapsulated as the form meeting instant communication server requirement, and pass through set up long connection and send to instant communication server.
Follow-up, how instant communication server is treated to prior art to the data received.
Step 14: after receiving instant communication server and returning to the data of client X, Relay Server utilizes long connection of setting up between self with client X that the data returned are sent to client X.
In this step, Relay Server is by being connected with the length set up between client X, and data instant communication server being returned to client X send to client X.
In addition, in embodiment illustrated in fig. 1, in order to saving resource, Relay Server also periodically can travel through set up between self with each client all long and be connected, and for each long connection Y traversed, determines whether it is in disabled state respectively, if not, then do not deal with, if, then send to the long Y of connection and wake instruction up, and determine whether to send successfully, if unsuccessful, then disconnect long connection Y, thus the resource discharged shared by it, if success, then do not deal with.
Wherein, for each long connection Y traversed, Relay Server can obtain its last active time, if the duration at interval is greater than the threshold value preset between this last active time and current time, then can determine that the long Y that connects is in disabled state (possible user's off-line).The concrete value of described threshold value can be decided according to the actual requirements.
Based on above-mentioned introduction, invention also provides a kind of instant communicating system.
Fig. 4 is the composition structural representation of instant communicating system embodiment of the present invention.As shown in Figure 4, comprising: client 41, Relay Server 42, operations server 43 and instant communication server 44; Wherein, the number of client 41 is more than one, namely one or more, for simplifying accompanying drawing, show but one in Fig. 4.
Each client X 41, is respectively used to after user utilizes and self logs in, and sets up and is connected with long between Relay Server 42; When user writes data at every turn, set up and be connected with short between operations server 43, the data of write are passed through set up short connection and send to operations server 43, and by receiving with long connection of setting up between Relay Server 42 data that instant communication server 44 that Relay Server 42 sends returns to self;
Operations server 43, for when after the data receiving write, sets up and is connected with short between Relay Server 42, and the data of write is passed through set up short connection and send to Relay Server 42;
Relay Server 42, for the data separate of write self is sent to instant communication server 44 with long connection of setting up between instant communication server 44, and after receiving instant communication server 44 and returning to the data of client X 41, utilize long connection of setting up between self with client X 41 that the data returned are sent to client X 41.
Above-mentioned Relay Server 42 also can be further used for, periodically travel through set up between self with each client 41 all long to be connected, for each long connection Y traversed, determine whether it is in disabled state respectively, if so, then send to the long Y of connection and wake instruction up, and determine whether to send successfully, if unsuccessful, then disconnect long connection Y.
Invention also provides a kind of client, comprising: the first processing unit and the second processing unit;
Wherein, the first processing unit, after utilizing as user and self logging in, sets up and is connected with long between Relay Server;
Second processing unit, for when user writes data at every turn, sets up and is connected with short between operations server, and the data of write is passed through set up short connection and send to operations server;
Above-mentioned first processing unit is further used for, and receives by described long connection the data that instant communication server that Relay Server sends returns to self.
Invention also provides a kind of Relay Server, comprising: the 3rd processing unit and fourth processing unit;
Wherein, 3rd processing unit, for the short data being connected user's write that reception operations server is sent by setting up between self with operations server, the data separate of write self is sent to instant communication server with long connection of setting up between instant communication server;
Fourth processing unit, for after receiving instant communication server and returning to the data of any client, utilizes long connection of setting up between self with this client that the data returned are sent to this client.
In addition, also can comprise further in this Relay Server:
5th processing unit, be connected for periodically traveling through set up between self with each client all long, for each long connection Y traversed, determine whether it is in disabled state respectively, if so, then send to the long Y of connection and wake instruction up, and determine whether to send successfully, if unsuccessful, then disconnect long connection Y.
Specifically, the 5th processing unit can obtain the long last active time connecting Y, if the duration at interval is greater than the threshold value preset between this last active time and current time, then determines that the long Y that connects is in disabled state.
The specific works flow process of said system and device embodiment please refer to the respective description in embodiment of the method shown in Fig. 1, repeats no more herein.
The foregoing is only preferred embodiment of the present invention, not in order to limit the present invention, within the spirit and principles in the present invention all, any amendment made, equivalent replacement, improvement etc., all should be included within the scope of protection of the invention.