Summary of the invention
A purpose of the present invention is to provide a kind of asynchronous socket means of communication, the transmission data integrity, and data can not run off; Accelerate the communication transmission speed; Guarantee that under the situation of unstable networks, the socket message queue can not block.
A purpose of the present invention is to provide a kind of mobile phone positioning system that adopts asynchronous socket communication, can tackle network and unsettled special status occur.
In order to achieve the above object, the invention provides a kind of asynchronous socket means of communication, described method comprises: asynchronous socket with the message deposit that receives in messaging list; Control described messaging list length by semaphore,, then continue to receive message if messaging list length does not reach the setting maximum; If messaging list length reaches the setting maximum, then lock described information list by described semaphore, the message in the messaging list is taken out and sent; And semaphore wakes described messaging list continuation reception message up after sending.
Wherein, in specific embodiment, described setting maximum is to set according to the speed that message sends, and guarantees that under the situation of unstable networks, the socket message queue can not block.Employing group crossfire form sends the message content in the messaging list, and described group of crossfire form is that the message in the messaging list is formed character string or code stream string.Described message is by disposable taking-up and transmission.Therefore, can accelerate transfer rate.
In one embodiment, described method also is included in and receives and transmission message, need carry out information translation according to the smpp agreement.
A kind of mobile phone positioning system that adopts asynchronous socket communication is provided, comprises: socket communication server, Service Processing Module, GIS server, sms center, and mobile phone terminal.Wherein, described mobile phone terminal is connected by mobile radio network with described sms center, can receive geographical location information and demonstration, and sends position enquiring information; Described GIS server provides the geographical location information service; Described sms center is set up the socket communication with described socket communication server and is connected, and transmits position enquiring information and geographical location information; Described Service Processing Module is connected by network with described GIS server, inquires about relevant geographical location information according to position enquiring information in described GIS server, and is transmitted to the socket communication server; Described socket communication server is to set up the socket communication respectively to connect between described sms center and described Service Processing Module, carry out information translation according to the information translation agreement, with the message deposit that receives in messaging list, control described messaging list length by semaphore:, then continue to receive message if messaging list length does not reach the setting maximum; If messaging list length reaches the setting maximum, then lock described information list by described semaphore, the message in the messaging list is taken out and sent, transmission back semaphore wakes described messaging list up and continues to receive message.
In specific embodiment, described agreement is the smpp agreement, is the conversion of decoding and encoding according to described Service Processing Module and the required information of sms center.Described setting maximum is to set according to the speed that message sends.Described socket communication server is that employing group crossfire form sends the message content in the messaging list, and described group of crossfire form is that the message in the messaging list is formed character string or code stream string.Message is by disposable taking-up and transmission in the described socket communication server.
A kind of asynchronous socket means of communication of the present invention have the following advantages: message deposit is in information list, and the socket message of transmission can not lost; The speed that transmits is accelerated in the disposable transmission of all message in the tabulation; Size according to actual conditions adjustment queue length guarantees that under the situation of unstable networks, the socket message queue can not block.A kind of mobile phone positioning system that adopts asynchronous socket communication of the present invention, on the basis of above-mentioned advantage, its positioning function can be tackled network and unsettled special status occur.
Embodiment
Below by specific instantiation explanation embodiments of the present invention, those skilled in the art can understand other advantages of the present invention and effect easily by the content that this specification disclosed.The present invention also can be implemented or used by other different instantiations, and the every details in this specification also can be based on different viewpoints and application, carries out various modifications and change under the purpose of the present invention not deviating from.
A kind of asynchronous socket means of communication of the present invention are to be applied in asynchronous socket communication field.
Seeing also Fig. 1, is to show asynchronous socket means of communication flow chart of the present invention, and as shown in the figure, a kind of asynchronous socket means of communication of present embodiment comprise:
Step S11, receiving thread continue to receive the data of another node or module transmission by socket;
Step S12 by the tabulation of semaphore control messages, judges whether messaging list length reaches the setting maximum;
Step S13, if messaging list length do not reach the setting maximum, then with the message deposit that receives in described messaging list, and then carry out step S11, promptly receiving thread continues to receive message;
Step S14 if messaging list length reaches the setting maximum, then locks described information list by semaphore;
Step S15 sends thread destination node is taken out and sent to the message in the messaging list;
Step S16, after message sent, semaphore woke described messaging list up, continued to receive message, and carried out step S12, and communication so circulates.
Wherein, in the present embodiment, described setting maximum is to set according to the speed that real messages sends, be that described setting maximum is variable, dynamic, for example, can set this setting maximum according to the speed that receives or send the last lower node place of message, can guarantee that like this under the situation of unstable networks, the socket message queue can not block.In addition, can also employing group crossfire form send the message content in the messaging list, described group of crossfire form is that the message in the messaging list is formed character string or code stream string, and described message is by disposable taking-up and transmission, therefore, can accelerate message transmission speed like this.
In the present embodiment, the described asynchronous socket means of communication also comprise: when receiving and send message, need carry out information translation according to the smpp agreement, promptly after receiving bottom data, need earlier it to be converted into the data that the upper strata needs by smpp information translation protocol-decoding, the same manner is changed in the other direction.
A kind of asynchronous socket means of communication of the present invention have the following advantages: message deposit is in information list, and the socket message of transmission can not lost; The speed that transmits is accelerated in the disposable transmission of all message in the tabulation; Size according to actual conditions adjustment queue length guarantees that under the situation of unstable networks, the socket message queue can not block.
See also Fig. 2, be to show that the present invention adopts the mobile phone positioning system block diagram of asynchronous socket communication, as shown in the figure, the invention provides a kind of mobile phone positioning system that adopts asynchronous socket communication, comprise: socket communication server 14, Service Processing Module 13, GIS server 11, sms center 12, and mobile phone terminal 10, wherein, described mobile phone terminal 10 and described sms center 12 are connected by mobile radio network, can receive geographical location information and demonstration, and send position enquiring information, promptly major function is to receive the message of sms center 12 transmissions and send message to sms center 12.Wherein, described mobile radio network can be GSM network or cdma network, or other communication network, and public network or private network all can.
Described GIS (GIS-Geographic Information System, Geographic Information System) server 11 provides the geographical location information service, for example the obtaining of geographic position data, store, show, service such as editor, processing, analysis, output and application.
Described sms center 12 is set up the socket communication with described socket communication server 14 and is connected, transmit position enquiring information and geographical location information, be that described sms center 12 major functions are that the information and sending that receives socket communication server 14 is given mobile phone terminal, and mobile phone is sent content be transmitted to socket communication server 14.
Described Service Processing Module 13 and described GIS server 11 are connected by network, inquire about relevant geographical location information according to position enquiring information in described GIS server 11, and are transmitted to socket communication server 14.The major function that is described Service Processing Module 13 is the message warehouse-in that receives socket communication server 14; The geographical location information of searching the user by described GIS server 11 sends to socket communication server 14; In addition, described Service Processing Module 13 can also send localization message to the socket communication server by webpage.
Described socket communication server 14 is to set up the socket communication respectively to connect between described sms center 12 and described Service Processing Module 13, it is to control described messaging list by semaphore that this socket communication connects: mainly be to judge whether messaging list length reaches the setting maximum, if reach the setting maximum, then lock described information list, message is sent the back semaphore wake described messaging list continuation reception message again up by described semaphore.
In the present embodiment, described agreement is the smpp agreement, is the conversion of decoding and encoding according to described Service Processing Module 13 and sms center 12 required information.Described setting maximum is to set according to the speed that message sends, and for example sets this setting maximum according to the speed of message sink in sms center 12 or the Service Processing Module 13 and transmission.Described socket communication server 14 is that employing group crossfire form sends the message content in the messaging list, and described group of crossfire form is that the message in the messaging list is formed character string or code stream string.Message is by disposable taking-up and transmission in the described socket communication server 14.
In actual applications, the mobile phone positioning system of the asynchronous socket communication of whole employing is disposed in the following way: realize whole system, need deployment socket communication server 14, Service Processing Module 13, sms center 12, GIS server 11, socket communication server 14 to set up the socket long-chain with sms center 12 and Service Processing Module 13 and connect, can send out message mutually; Mobile phone terminal 10 can send out positioning command message or positional information is given sms center 12, and sms center 12 sends to socket communication server 14; Service Processing Module 13 shows on map according to the legitimacy of verification consumer positioning with according to position enquiring information inquiry GIS server 11, or converts geographical location information to.
The step of the mobile phone positioning system of the asynchronous socket communication of whole employing operation can be, for example:
1, socket communication server 14 starts, and foundation is connected with sms center 12 with Service Processing Module 13 and is connected.
Sms center 12 is set up socket with socket communication server 14 and is connected, and starts a thread and detects heartbeat, and one sends thread, a receiving thread.
Socket communication server 14 is opened listening port, sets up to be connected with Service Processing Module 13, starts one and sends thread and receiving thread.
2, mobile phone terminal 10 by sms center 12 send position requests or position enquiring information to socket communication server 14 after, socket communication server 14 is deposited in message content in the messaging list.
3, by semaphore control information list length, reach locking information tabulation after the maximum, send the follow-up messaging list content of continuing.
4, come the setup message list length according to the message transmission speed, reach transmission speed and do not produce the equilibrium value that message is blocked.
5, socket communication server 14 once takes out the composition crossfire to the messaging list content and sends to Service Processing Module 13, accelerates message transmission speed.
6, Service Processing Module 13 is gone into database, carries out the user validation verification or according to position enquiring information GIS server 11 inquiring user positional informations.
7, Service Processing Module 13 sends to socket communication server 14 to message, and socket communication server 14 utilizes socket that message is sent to sms center 12 according to step 2-5 again.
8, sms center 12 sends to mobile phone terminal 10 by wireless network, thereby finishes the function of mobile phone terminal location.
In sum, a kind of asynchronous socket means of communication of the present invention, be to lock and the wakeup message formation by semaphore, it can be the socket communication of a large amount of interacting messages between the disparate modules of two nodes or same node, message deposit in messaging list, thread is got list message and is formed character string or the transmission of code stream string, and when messaging list length arrived the setting maximum, semaphore pinned tabulation, after sending message, semaphore wakes thread up and resumes operation, and therefore, has accelerated the speed of transfer of data, especially at the network service less stable, when socket blocks, promptly prevent losing of information, guaranteed the smooth communication of socket.The mobile phone positioning system that adopts asynchronous socket communication makes the mobile phone location can tackle network and unsettled special status occurs on above-mentioned advantage basis, is fit to the application under the particular surroundings more.
The above-mentioned description to embodiment is can understand and use the present invention for ease of those skilled in the art.The person skilled in the art obviously can make various modifications to these embodiment soon, and needn't pass through performing creative labour being applied in the General Principle of this explanation among other embodiment.Therefore, the invention is not restricted to the embodiment here, those skilled in the art should be within protection scope of the present invention for improvement and modification that the present invention makes according to announcement of the present invention.