Summary of the invention
An object of the present invention is to provide a kind of asynchronous socket communication method, transmission data integrity, and can not run off data; Accelerate communication transfer speed; Ensure that, when unstable networks, socket message queue can not block.
An object of the present invention is to provide a kind of mobile phone positioning system adopting asynchronous socket communication, can tackle network and occur unstable special status.
In order to achieve the above object, the invention provides a kind of asynchronous socket communication method, described method comprises: asynchronous socket by the message deposit that receives in messaging list; Control described messaging list length by semaphore, if messaging list length does not reach setting maximum, then continue receipt message; If messaging list length reaches setting maximum, then lock described information list by described semaphore, the message in messaging list is taken out and sends; And semaphore wakes described messaging list continuation receipt message up after sending.
Wherein, in a particular embodiment, described setting maximum is that the speed sent according to message sets, and ensures that, when unstable networks, socket message queue can not block.Employing group crossfire form sends the message content in messaging list, and described group of crossfire form is by the message composition character string in messaging list or code stream string.Described message is by disposable taking-up and send.Therefore, transfer rate can be accelerated.
In one embodiment, described method is also included in and receives and send message, needs to carry out information conversion according to smpp agreement.
A kind of mobile phone positioning system adopting 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 show, and sends position enquiring information; Described GIS server provides geographical location information service; Described sms center is set up socket communication with described socket communication server and is connected, and forwards 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, and be transmitted to socket communication server according to position enquiring information in described GIS server; Described socket communication server between described sms center and described Service Processing Module, sets up socket communication respectively connect, information conversion is carried out according to information translation-protocol, by the message deposit that receives in messaging list, described messaging list length is controlled: if messaging list length does not reach setting maximum, then continue receipt message by semaphore; If messaging list length reaches setting maximum, then lock described information list by described semaphore, the message in messaging list taken out and send, after sending, semaphore wakes described messaging list continuation receipt message up.
In a particular embodiment, described agreement is smpp agreement, is the conversion that information needed for described Service Processing Module and sms center carries out decoding and encoding.Described setting maximum is that the speed sent according to message sets.Described socket communication server be employing group crossfire form to send the message content in messaging list, described group of crossfire form is by the message composition character string in messaging list or code stream string.Message is sent by disposable taking-up in described socket communication server.
The asynchronous socket communication method of one of the present invention, has the following advantages: message deposit is in information list, and the socket message of transmission can not be lost; The disposable transmission of all message in list, accelerates the speed transmitted; According to the size of actual conditions adjustment queue length, ensure that, when unstable networks, socket message queue can not block.A kind of mobile phone positioning system adopting asynchronous socket communication of the present invention, on the basis of above-mentioned advantage, its positioning function can be tackled network and occur unstable special status.
Embodiment
Below by way of specific instantiation, embodiments of the present invention are described, those skilled in the art can understand other advantages of the present invention and effect easily by content disclosed in the present specification.The present invention is also implemented by other different instantiations or is applied, and the every details in this specification also can based on different viewpoints and application, carries out various modification and change not deviating under object of the present invention.
One of the present invention asynchronous socket communication method is applied in asynchronous socket communication field.
Refer to Fig. 1, be display asynchronous socket communication method flow diagram of the present invention, as shown in the figure, the asynchronous socket communication method of one of the present embodiment comprises:
Step S11, the data that receiving thread is sent by another node of socket continuous reception or module;
Step S12, by the list of semaphore control message, judges whether messaging list length reaches setting maximum;
Step S13, if messaging list length does not reach setting maximum, then by the message deposit that receives in described messaging list, and then carry out step S11, namely receiving thread continues receipt message;
Step S14, if messaging list length reaches setting maximum, then locks described information list by semaphore;
Step S15, sends thread and the message in messaging list is taken out and be sent to destination node;
Step S16, after message sends, semaphore wakes described messaging list up, and continue receipt message, and carry out step S12, so circulate communication.
Wherein, in the present embodiment, described setting maximum is that the speed sent according to real messages sets, namely described setting maximum is variable, dynamic, such as, this setting maximum can be set according to the speed of the Nodes up and down receiving or send message, can ensure that, when unstable networks, socket message queue can not block like this.In addition, group crossfire form can also be adopted to send the message content in messaging list, described group of crossfire form is by the message composition character string in messaging list or code stream string, and described message is sent by disposable taking-up, therefore, message transmission speed can be accelerated like this.
In the present embodiment, described asynchronous socket communication method also comprises: when receiving and send message, need to carry out information conversion according to smpp agreement, namely after receiving bottom data, need the data first it being converted into upper strata needs by the decoding of smpp information translation-protocol, the same manner is changed in the other direction.
The asynchronous socket communication method of one of the present invention, has the following advantages: message deposit is in information list, and the socket message of transmission can not be lost; The disposable transmission of all message in list, accelerates the speed transmitted; According to the size of actual conditions adjustment queue length, ensure that, when unstable networks, socket message queue can not block.
Refer to Fig. 2, it is the mobile phone positioning system block diagram that display the present invention adopts asynchronous socket communication, as shown in the figure, the invention provides a kind of mobile phone positioning system adopting 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 is connected by mobile radio network with described sms center 12, can geographical location information be received and show, and send position enquiring information, namely major function is the message of reception sms center 12 transmission and sends message to sms center 12.Wherein, described mobile radio network can be GSM network or cdma network, or other communication network, public network or private network.
Described GIS (GIS-Geographic Information System, Geographic Information System) server 11 provides geographical location information service, the acquisition of such as geographic position data, storage, display, editor, process, analysis, the service such as output and application.
Described sms center 12 is set up socket communication with described socket communication server 14 and is connected, forward position enquiring information and geographical location information, namely described sms center 12 major function be receive socket communication server 14 information and sending to mobile phone terminal, and mobile phone is sent content and is transmitted to socket communication server 14.
Described Service Processing Module 13 is connected by network with described GIS server 11, inquires about relevant geographical location information, and be transmitted to socket communication server 14 according to position enquiring information in described GIS server 11.Namely the major function of described Service Processing Module 13 is the message warehouse-ins receiving socket communication server 14; The geographical location information searching 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 socket communication server by webpage.
Described socket communication server 14 between described sms center 12 and described Service Processing Module 13, sets up socket communication respectively connect, it is control described messaging list by semaphore that this socket communication connects: mainly judge whether messaging list length reaches setting maximum, if reach setting maximum, then lock described information list by described semaphore, after message being sent, semaphore wakes described messaging list continuation receipt message again up.
In the present embodiment, described agreement is smpp agreement, is the conversion that information needed for described Service Processing Module 13 and sms center 12 carries out decoding and encoding.Described setting maximum is that the speed sent according to message sets, such as, set this setting maximum according to the speed of the message sink in sms center 12 or Service Processing Module 13 and transmission.Described socket communication server 14 be employing group crossfire form to send the message content in messaging list, described group of crossfire form is by the message composition character string in messaging list or code stream string.Message is sent by disposable taking-up in 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, socket communication server 14 need be disposed, Service Processing Module 13, sms center 12, GIS server 11, socket communication server 14 set up socket long-chain with sms center 12 and Service Processing Module 13 and connect, message can be sent out mutually; Mobile phone terminal 10 can send out relocation command message or positional information to sms center 12, and sms center 12 sends to socket communication server 14; Service Processing Module 13 is according to the legitimacy of verification consumer positioning and show on map according to position enquiring information inquiry GIS server 11, or converts geographical location information to.
The step that the mobile phone positioning system of the asynchronous socket communication of whole employing runs can be, such as:
1, socket communication server 14 starts, and foundation is connected with Service Processing Module 13 and sms center 12 connects.
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 opens listening port, sets up and is connected with Service Processing Module 13, starts one and sends thread and receiving thread.
2, mobile phone terminal 10 sends position requests or position enquiring information to after socket communication server 14 by sms center 12, and socket communication server 14 is deposited in message content in messaging list.
3, by semaphore control information list length, reach locking information list after maximum, send and follow-uply continue messaging list content.
4, carry out setup message list length according to message transmission speed, reach transmission speed and do not produce the equilibrium value of message blocking.
5, socket communication server 14 once takes out composition crossfire messaging list content and sends to Service Processing Module 13, accelerates message transmission speed.
6, Service Processing Module 13 enters database, carries out user validation verification or according to position enquiring information GIS server 11 inquiring user positional information.
7, Service Processing Module 13 sends to socket communication server 14 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, thus completes the function of mobile phone terminal location.
In sum, the asynchronous socket communication method of one of the present invention, locked and wakeup message queue by semaphore, can be two nodes or same node disparate modules between the socket communication of a large amount of interacting message, message deposit in messaging list, thread is got list message and is formed character string or the transmission of code stream string, when messaging list length arrives setting maximum, semaphore pins list, after sending message, semaphore wakes thread up and resumes operation, therefore, accelerate the speed of transfer of data, especially at network service less stable, time socket blocks, namely the loss of information is prevented, ensure that the smooth communication of socket.Adopt the mobile phone positioning system of asynchronous socket communication on above-mentioned advantage basis, mobile phone is located and can tackle the unstable special status of network appearance, be more applicable to the application under particular surroundings.
Above-mentioned is can understand for ease of those skilled in the art and use the present invention to the description of embodiment.Person skilled in the art obviously can make various amendment to these embodiments soon, and General Principle described herein is applied in other embodiments and need not through performing creative labour.Therefore, the invention is not restricted to embodiment here, those skilled in the art are according to announcement of the present invention, and the improvement made for the present invention and amendment all should within protection scope of the present invention.