A kind of information transferring method between client and server-side
Technical field
The present invention relates to technical field of information processing, more specifically, it relates between a kind of client and server-side
Information transferring method.
Background technique
Big amount of access, high concurrent large-scale website in, the consumption of the thread of Web server is very serious, thread money
Ten code insurance of source is expensive, how to improve thread utilization rate, improves the key point that the responding ability requested is often web site performance optimization.But
The operation of some high concurrents, high time-consuming, low real-time is had in systems and usually, and the result of these operations is for website user
For do not need to timely feedback, but if webpage wait these simultaneously operatings return, to thread occupy and respond have
Serious influence reduces the handling capacity of service.
Therefore asynchronous process generally is carried out using the operation of Microsoft Message queue (MSMQ) to height consumption now, by using
Another process that message queue can be routed to message to be processed on the machine or other machine is handled, this
Mode provides better resource expansion.It is handled, can be reduced to local resource by the way that message is routed to other machine
Consumption, while asynchronous provided by message queue and offline mechanism can preferably improve the responding ability of main program.
However, when carrying out asynchronous information transmission by interconnected network between different machines, it can be due to being responsible for
The network of transmission generates the interruption of information transmission because of the failure surprisingly generated therewith, not can guarantee information after resuming normal biography
Defeated, reliability and efficiency to work generate strong influence.
Summary of the invention
In view of the above-mentioned problems, the purpose of the present invention is to provide the information transmission sides between a kind of client and server-side
Method has the advantages that highly reliable, high-efficient.
Foregoing invention purpose of the invention has the technical scheme that
A kind of information transferring method between client and server-side, includes the following steps:
S1: the request message of asynchronous process to be carried out is transferred to corresponding server-side, the clothes by general purpose routine by client
Business end returns to response message to the client by the general purpose routine;
S2: the request message of asynchronous process to be carried out is transferred to corresponding server-side, the clothes by spare module by client
Business end returns to response message to the client by the spare module.
It is transmitted through the above technical solutions, client can be realized by general purpose routine first with the signal of server-side, when logical
Broken down with path, can there is spare module to continue to transmit, guarantee information processing it is reliable with it is efficient.
The present invention is further arranged to: the step S1 is specifically included:
S11: the client request message is written in the server-side MSMQ;
S12: the processing module of the server-side is answered by described in after reading the request message stored in the server-side MSMQ
Message is answered to be written in the server-side MSMQ;
S13: the client MSMQ reads the response message.
Through the above technical solutions, asynchronous transmission processing is carried out by operation of the message queue to height consumption, it can be more preferable
The main solicited message of processing and corresponding response message, the responding ability of main program can be promoted.
The present invention is further arranged to: the step S2 is specifically included:
S21: the spare module initialization;
S22: the request message is written in the server-side MSMQ by the spare module for the client;
S23: the processing module of the server-side is answered by described in after reading the request message stored in the server-side MSMQ
Message is answered to be written in the server-side MSMQ;
S24: the client MSMQ reads the response message by the spare module.
Through the above technical solutions, if Transmission in S1 and can not continue to complete, enable spare module and carry out letter
Breath continues to transmit, and realizes the information exchange of client and server-side.
The present invention is further arranged to: the spare module is TCP service module, including being arranged in the client
TCP Client and the TCP server-side being arranged in the server-side, the step S21 are specifically included:
S211: the TCP server-side opens TCP port and the transmitting terminal of TCP Client establishes connection, waits number of request to be received
According to.
Through the above technical solutions, windows system itself has TCP service and possesses corresponding TCP port, TCP sheet
Body is a kind of transmission control protocol, has corresponding data transport service, easy to use, stability is strong.
The present invention is further arranged to: the step S22 is specifically included:
S221: the solicited message is translated into the request data that the TCP server-side can identify by the client, and
It is received and is sent by the TCP Client;
S222: the request data is translated into the server-side MSMQ energy after the TCP server-side reception request data
The request message enough identified is written in the server-side MSMQ.
Through the above technical solutions, communication can be realized at the solicited message write service end of client.
The present invention is further arranged to: the step S24 is specifically included:
S241: the processing module of the server-side is translated after reading the response message stored in the server-side MSMQ
The reply data that can be identified at the TCP server-side;
S242: the TCP Client is transcribed into the institute that the client MSMQ can be identified after reading the reply data
Response message is stated, and the response message is stored in the client MSMQ.
Through the above technical solutions, client can be written the response message of server-side, reversed communication or feedback are realized.
The present invention is further arranged to: the write operation application Windows communication infrastructure of message queue in the step S11
WCF is handled.
Compared with prior art, the beneficial effects of the present invention are:
By the way that two communication lines are arranged, more processing times are provided to main operational objective in a manner of asynchronous transmission information
And space, the unnecessary wasting of resources is reduced, and wherein after a communication line interrupt, it can be by another communication line not
The transmission for continuing data in the case where original function is influenced, it is practical and convenient reliable.
Detailed description of the invention
Fig. 1 is the flow diagram of embodiment in the present invention;
Fig. 2 is the flow diagram of embodiment in the present invention.
Specific embodiment
With reference to the accompanying drawings and examples, the present invention will be described in detail.
A kind of information transferring method between client and server-side, thinking are to provide two kinds of reliable data transmission ways
Diameter, realizes the efficient communication transmission of information between two information transmit-receive components, such as realizes that MS client (is grasped based on Windows
Make the Maneger System client of system) and CC server-side (Control Center, control centre) efficient communication, such as
Shown in Fig. 1, include the following steps:
The request message of asynchronous process to be carried out is transferred to corresponding server-side by general purpose routine by step S1, client, clothes
Business end returns to response message to client by general purpose routine.If server-side can not by request message transmission to server-side, into
Enter step S2.
Step S2: the request message of asynchronous process to be carried out is transferred to corresponding service by spare module by client
End, server-side return to response message to client by spare module.Continue to guarantee client and server-side by spare module
High efficiency communication, it is simple and reliable.
Above-mentioned steps S1 is specifically included:
Step S11: client is by Windows operating system, and the address of service provided according to server-side, request message road
By to after server-side, request message write service end MSMQ(MicroSoft Message Queue, Microsoft Message queue) in
It is stored, enters back into step S12.
Step S12: the request message that the processing module of server-side can be called and be stored in the MSMQ of reading service end, it can be with
Generate immediately can also postpone generate response message after in the MSMQ of write service end, avoid unnecessary information processing from occupying whole
The time is handled, the responding ability of communication efficiency and main program is promoted.
Step S13: client MSMQ reads response message.Above-mentioned and next MSMQ(Microsoft Message queue)
Write-in and extraction can pass through WCF (Windows Communication Foundation, Windows the communication base using Microsoft
Plinth) technology is uniformly processed.
Spare module includes the TCP Client being arranged in client and the TCP server-side that is arranged in server-side, when upper
The general purpose routine stated breaks down, and can pass through a kind of transmission control protocol of TCP() service module as spare module after resuming
It is defeated, TCP service is itself had using windows system and possesses the advantage of corresponding TCP port, in conjunction with the asynchronous transmission of MSMQ
Function guarantees that the other end that can be transmitted from one end of data, stability are stronger.
Step S2 is specifically included:
Connection is established with the transmitting terminal of TCP Client after the port initialization of step S21:TCP server-side, waits number of request to be received
According to.
Step S22: client by spare module by request message write service end MSMQ, because of the client of TCP
It can not identify the solicited message directly from client MSMQ, need to enter step S221.
Step S221: solicited message is translated into the request data that TCP server-side can identify by client, and by TCP visitor
Family end receives and sends, which changes into Json format after being packaged into object (TtansferTCP) by client, due to adopting
Data are stored and indicated with the text formatting for being totally independent of programming language, and hierarchical structure is succinctly and clear, so that Json
As ideal data interchange language, it is easy to people and reads and write, while being also easy to machine parsing and generating, can be effectively promoted
Data transmission efficiency.S222 is entered step while sending request data to TCP server-side.
After step S222:TCP server-side receives request data, request data is now translated into MQ data, write service end
In MSMQ.When server-side needs to call request message in server-side MSMQ, S23 is entered step.
Step S23: it after the request message stored in the processing module reading service end MSMQ of server-side, generates response and disappears
Breath, then by response message write service end MSMQ, and make it into state to be sent.It carries out sending the response if necessary,
Enter step S24.
Step S24: client MSMQ reads response message by spare module.In this process, likewise, passing through
It needs first to be packaged translation when TCP is to client transmissions response message, enters step S241.
Step S241: the response message stored in the processing module reading service end MSMQ of server-side will dress up object
(TtansferTCP) S242 is entered step after changing into the reply data of Json format after.
Step S242:TCP client converts thereof into MQ data after reading reply data again, and reconvert is at client MSMQ
It can identify received MQ data, send and be stored in client MSMQ, the extraction of client is waited to use.
The above is only a preferred embodiment of the present invention, protection scope of the present invention is not limited merely to above-mentioned implementation
Example, all technical solutions belonged under thinking of the present invention all belong to the scope of protection of the present invention.It should be pointed out that for the art
Those of ordinary skill for, several improvements and modifications without departing from the principles of the present invention, these improvements and modifications
It should be regarded as protection scope of the present invention.