A kind of method for connecting network and device and computer systemTechnical field
The present invention relates to field of computer technology, more particularly to a kind of method for connecting network and device and department of computer scienceSystem.
Background technology
Increasing with the scale of software systems, most of system can all do load in front end using reverse proxyWeighing apparatus.But for the client computer for being communicated with hardware, Socket long connections are that only there are one physical connections.And evenConnect the server-side and client needed by Socket connections are established, it is impossible to accomplish arbitrary calling.
After HTTP request reaches Reverse Proxy, request is distributed to service by Reverse Proxy according to ruleDevice.If HTTP request is distributed to server 1, and HTTP request is wanted to communicate with the Socket of client computer 1, thisWhen, it is necessary to server 1 is established into a Socket with client computer and is connected, as shown in Figure 1, Fig. 1 is net according to prior artNetwork connection diagram.
But in actual motion, it is uncertain which platform server is HTTP request, which be distributed to, if it is desired to every serviceDevice can handle the request of arbitrary reception, it is necessary to do the Socket long connections of each client computer once on each serverConnection, not only wastes system resource, while is also unfavorable for system level extension.
The content of the invention
In view of this, the present invention provides a kind of method for connecting network and device and computer system, solves each visitorThe problem of family machine is required for establishing connection respectively with each server simplifies the connection between server and client computer, makes clothesBusiness device and client machine system resource utilization substantially reduce, and existing program need not be repaiied in number of servers increaseChange, extended beneficial to system level.
To achieve the above object, according to an aspect of the invention, there is provided a kind of method for connecting network.
The method for connecting network of the present invention includes:Receive the solicited message that request is attached with specified client;It determinesThe server being connected with the specified client;The solicited message is distributed to the server.
Optionally it is determined that be connected with the specified client server the step of include:From the server of preservation withServer corresponding with specified client is inquired in the connection relation information of client computer.
Optionally, the connection relation information is using client identifying as key, using server identification as the key assignments of valueIt is right.
Optionally, the client identifying is IP address.
Optionally, the solicited message includes HTTP request information;The connection includes Socket connections.
According to another aspect of the present invention, a kind of network connection device is provided.
The network connection device of the present invention includes:Receiving module asks what is be attached with specified client for receivingSolicited message;Determining module, for determining the server being connected with specified client;Distribution module, for by the requestInformation is distributed to the server.
Optionally, the determining module is additionally operable to inquire from the connection relation information of the server of preservation and client computerServer corresponding with specified client.
According to another aspect of the present invention, a kind of computer system is provided.
The computer system of the present invention includes:Reverse proxy, multiple servers and multiple client computer, wherein, reversed generationReason, for receiving the solicited message that request and specified client are attached;Determine the clothes being connected with the specified clientBusiness device;The solicited message is distributed to the server;Each server is connected respectively with the reverse proxy, for receivingState the solicited message of reverse proxy distribution;Each client computer is connected respectively with a server.
Optionally, storage device is further included, for storing the connection relation information of the client computer and the server.
Optionally, the storage mode of the connection relation information is caching, file, database or program variable.
Technique according to the invention scheme after the solicited message that request is attached with specified client is received, passes throughDetermine the server being connected with the specified client so that make each client computer woth no need to be established respectively with each serverConnection, simplifies the connection between server and client computer, substantially reduces server and client machine system resource utilization, andAnd existing program need not be made an amendment in number of servers increase, it is extended beneficial to system level.
Description of the drawings
Attached drawing does not form inappropriate limitation of the present invention for more fully understanding the present invention.Wherein:
Fig. 1 is network connection schematic diagram according to prior art;
Fig. 2 is computer system schematic diagram according to embodiments of the present invention;
Fig. 3 is method for connecting network schematic diagram according to embodiments of the present invention;
Fig. 4 is network connection device schematic diagram according to embodiments of the present invention.
Specific embodiment
It explains below in conjunction with attached drawing to the exemplary embodiment of the present invention, including the various of the embodiment of the present inventionDetails should think them only exemplary to help understanding.Therefore, those of ordinary skill in the art should recognizeIt arrives, various changes and modifications can be made to the embodiments described herein, without departing from scope and spirit of the present invention.TogetherFor clarity and conciseness, the description to known function and structure is omitted in sample in following description.
Fig. 2 is computer system schematic diagram according to embodiments of the present invention.As shown in Fig. 2, the calculating of the embodiment of the present inventionMachine system 20 mainly includes reverse proxy 21, multiple servers 22 and multiple client computer 23.Reverse proxy 21 please for receivingSeek the solicited message being attached with specified client;Determine the server 22 being connected with the specified client;By described inSolicited message is distributed to the server 22;Each server 22 is connected respectively with reverse proxy 21, for receiving the reversed generationThe solicited message of 21 distribution of reason;Each client computer 23 is connected respectively with a server 22.
Computer system 20 may also include storage device (not shown), for storing the client computer and the serviceThe connection relation information of device.The storage device can be an individual cache server, and caching read-write is by key-value pairMode carries out;Data can so be accomplished to atomicity, all programs can ensure correct, consistent in reading cache data.The storage mode of connection relation information can be caching, file, database or program variable etc..
Fig. 3 is method for connecting network schematic diagram according to embodiments of the present invention.This method is performed by reverse proxy 21, such asShown in Fig. 3, this method mainly includes steps S30 to S32.
Step S30:Receive the solicited message that request is attached with specified client.Request packet in the present embodimentHTTP request information is included, connection includes Socket connections.
Step S31:Determine the server being connected with specified client.The connection of server and client computer from preservation is closedIt is that server corresponding with specified client is inquired in information;Wherein, connection relation information be using client identifying as key,Using server identification as the key-value pair of value.Here, using the IP of client computer as key, service IP is stored in as the key-value pair of valueIn connection relation information.In this way, the Socket connection data that each client computer has connected are saved in connection relation information.WhenWhen receiving the HTTP request that request is attached with specified client, the IP institutes by checking client computer in connection relation information are rightServer ip is answered, just can determine that needs the HTTP request which platform server be distributed to, and therefore, server and client computer need not be keptMultiple connections substantially reduce server and client machine system resource utilization.In addition, if increase server/client, nothingExisting program need to be made an amendment, it is only necessary in connection relation information addition increased server/client link information.
Step S32:The solicited message is distributed to the server.And then server can send out solicited messageClient computer is given, realizes the network connection of requesting party and specified client.
Fig. 4 is network connection device schematic diagram according to embodiments of the present invention.The device can be arranged on instead as softwareInto agency 21.As shown in figure 4, the network connection device 40 of the embodiment of the present invention mainly includes receiving module 41, determining module42 and distribution module 43.The solicited message that receiving module 41 is attached for reception request with specified client;Determine mouldBlock 42 is for the definite server being connected with specified client;It can also be used to close from the server of preservation and the connection of client computerIt is that server corresponding with specified client is inquired in information;Distribution module 43 is used to solicited message being distributed to corresponding clothesBusiness device.
Technical solution according to embodiments of the present invention, in the solicited message that reception request is attached with specified clientAfterwards, pass through and determine the server that is connected with the specified client so that make each client computer woth no need to each serverConnection is established respectively, is simplified the connection between server and client computer, is made server and client machine system resource utilization bigIt is big to reduce, and existing program need not be made an amendment in number of servers increase, it is extended beneficial to system level.
The basic principle of the present invention is described above in association with specific embodiment, in apparatus and method of the present invention, it is clear thatEach component or each step can be decomposed and/or reconfigured.These decompose and/or reconfigure should be regarded as the present invention etc.Efficacious prescriptions case.Also, the step of performing above-mentioned series of processes can perform in chronological order according to the order of explanation naturally, stillAnd it need not centainly perform sequentially in time.Some steps can perform parallel or independently of one another.
Above-mentioned specific embodiment, does not form limiting the scope of the invention.Those skilled in the art should be brightIt is white, depending on design requirement and other factors, various modifications, combination, sub-portfolio and replacement can occur.It is anyModifications, equivalent substitutions and improvements made within the spirit and principles in the present invention etc., should be included in the scope of the present inventionWithin.