Background technology
In the gateway communication technology; Gateway and peripheral system SP (ServiceProvider, service provider), SMSC (Short Message Service Center, SMS service center) and other SMG (Short Message Gateway; Short messaging gateway) etc. all be towards connecting (TCP (Transmission Control Prot ocol; Transmission control protocol)/IP (Internet Protocol, IP(Internet Protocol))) communication mode, with the correctness that has guaranteed that information is transmitted.But in order to realize the communication mode of TCP/IP, need to use message queue and shared drive, to guarantee connection.It specifically stores the data that pass over through message queue, and writes the reply data that sends to the other side and reply row, in addition, also need be written to shared drive to some shared configuration informations of system and visit for other process.Like this, create some message queues and shared drive through regular meeting in the system, connect for communication and use.Shown in accompanying drawing 1.
But no matter be the message queue or the communication mode of shared drive, all have defective.Particularly, the quantity of message queue receives main frame restriction with size, and shared drive take Installed System Memory can not be too big, if influence the performance of system after too big.
And under HP-UX (the Hewlett Packard UniX) environment, because resource limit, message queue quantity, size all can be restricted.If the quantity of message queue or size are not enough, not only can reduce systematic function, possibly also can lead to system abnormity when serious.Therefore, need a kind of other communication mode,, improve the performance of system, and guarantee the reliability of communication to overcome the defective of above-mentioned communication mode.
Summary of the invention
The object of the invention is just in order to provide a kind of gateway communication method and device; Avoid when process communication, receiving the restriction of message queue quantity, size requirements; Thereby reduce the consumption of system resource, improve the security performance of system, and promote the efficiency of transmission of data.
On the one hand, the embodiment of the invention provides a kind of gateway communication method, and this gateway communication method may further comprise the steps:
Step (1): open the user datagram protocol UDP socket that is connected that is used to set up between gateway and the peripheral system;
Step (2): the destination address that specific data sends, set up being connected between gateway and the peripheral system;
Step (3): said gateway sends data to the UDP buffer, and said data send to destination address through said UDP buffer, and are received by said peripheral system;
Step (4): said gateway receives the return data of said destination address, and is saved in the local address that connects;
Step (5): whether the judgment data transmission finishes, if get into step (6), if not, then return step (3);
Step (6): break off the said socket that has connected.
On the other hand, the embodiment of the invention provides a kind of gateway communication device, and this gateway communication device comprises:
Be used to open the device that is used to set up the user datagram protocol UDP socket that is connected between gateway and the peripheral system;
Be used in reference to the destination address that given data is sent, and set up the device that is connected between gateway and the peripheral system;
Be used for sending to the UDP buffer device of data, said data send to destination address through said UDP buffer, and are received by said peripheral system;
Be used to receive the return data of said destination address, and be saved in the device of the local address that connects;
Be used for the judgment data transmission and whether finish, if, carry out to connect and break off module, if not, then proceed the device of transfer of data;
Be used to break off the device of the socket that has connected.
Gateway communication method provided by the invention and device can avoid when process communication, receiving the restriction of message queue quantity, size requirements, thereby reduce the consumption of system resource, improve the security performance of system, and promote the efficiency of transmission of data.
Embodiment
Be example with handling process below, specify the steps flow chart of communication means at letter gateway MO (short message transmit telephone bill).
In the MO treatment progress, like the smpp_ICP process, the peripheral system that send to the information of receiving from sms center: SP (service provider) or SPMS (COS has the spare parts management service).During communication; Adopt long the connection between gateway and the peripheral systems such as SP, SPMS; Pass through User Datagram Protocol (User Datagram Protocol between smpp_ICP process and the other side's process (as: slsSndD process); Being called for short " UDP ") mode carries out interprocess communication: as client, the slsSndD process receives the message of UDP formation as service end, sends to corresponding peripheral system to message by the slsSndD process again by smpp_ICP.
After the common customer end is opened socket, use socket----->sendto ()/recvfrom to send data usually, and Home Network pass system adopts be UDP connection mode socket----->connect ()----->send/recv sends data.
Function definition is following:
int?send(int?s,const?void?*msg,size_t?len,int?flags);
int?send?to(int?s,const?void?*msg,size_t?len,int?flags,const?struct?sockaddr?*to,socklen_t?tolen);
int?recv(int?s,void?*buf,size_t?len,int?flags);
int?recvfrom(int?s,void?*buf,size_t?len,int?flags,struct?sockaddr?*from,socklen_t?*fromlen);
Can find out from function definition: sendto and recvfrom be assigned address when transmitting-receiving; Send and recv then do not have; Use function int connect (int sockfd for this reason; Const struct sockaddr * serv_addr, socklen_taddr len), specify the destination address of transmission through the connect function.Like this, whether kernel just inspection exists the mistake that can know immediately, and the IP address and the port numbers (taking from the socket addresses structure that passes to connect) of record opposite end turn back to calling process then immediately.For connecting the UDP socket, compare with the default socket that is not connected, following variation has taken place:
(1) do not use sendto and use send or write; Mean when noting be used in each transmission and all specify host IP and port numbers, all send to protocol address (for example IP address and port numbers) automatically by the connect appointment and write writes any content that connects on the UDP socket.
(2) obtain data through read or recv; Can connect at one and only receive those packets on the UDP socket from the specified protocol address of connect; And needn't use recvfrom to learn the sender of datagram; The destination of Data Receiving has been for this has connected the native protocol address of UDP socket, and the packet of the data protocol address that not to be the previous connect of this socket arrive with sending just can not be delivered to this socket.So just limited one connected the UDP socket and also only can with an opposite end exchange data packets.
(3) when appearance is unusual, the asynchronous mistake that is caused by the UDP socket that has connected returns to the process that their belong to.
Concrete communication steps is following:
(1): open the UDP socket that is connected that is used to set up between gateway and the peripheral system, can use the socket socket.
(2): the destination address that specific data sends, set up being connected between gateway and the peripheral system, promptly use connect to connect.
(3): gateway sends data to the UDP buffer, and data send to destination address through the UDP buffer, are received by peripheral system; At this moment; The data of using send or write to write buffer all can send to peripheral system, are received by peripheral system, shown in accompanying drawing 3.
(4): the return data of receiving target address, and be saved in the local address that connects, gateway receives the data from peripheral system through recv or read, and is kept at this locality.
(5): whether the judgment data transmission finishes, if get into step (6), if not, then return step (3);
(6): break off the socket that has connected, connect, be set to AF_UNSPEC to the address of socket addresses structure bunch member (sin_family) when calling connect once more in order to break off a UDP socket that has connected connect.What make socket disconnection connection is the process of calling connect on the UDP socket connecting.
During concrete the realization, in the smpp_ICP process, realize transmission through UDP technology completion client data by int sgip_longsnd (int cmd, int dstid, char * sndbuf, int len, char * rcvbuf) function.In concrete communication process, call api function by operation layer, submit message through UDP to communication process (slsSndD), communication process is through message queue echo reply message.The concrete definition of this api function is following:
int?sgip_longsnd(int?cmd,int?dstid,char?*sndbuf,int?len,char*rcvbuf)
Input parameter:
Cmd: send the ID of message, i.e. the command_ID of SGIP (Short Message Gateway Interface Protocol, Short message Gateway Interface Protocol) message
Dstid: the order ground node code of message
Sndbuf: the SGIP message of transmission, PDU form
The len:sndbuf message-length
Output parameter:
Rcvbuf: response message, PDU (Protocol Data Unit, protocol Data Unit) form
Return value: message is sent result, the Result of corresponding response packet
The client part example code
Server end partial code example
The beneficial effect that the present invention obtained is: 1) selected after the opposite end through connect, kernel only can be passed to socket with the opposite end data sent bag of bound object, has therefore promoted the fail safe of system; 2) if unusually, can return asynchronous mistake.Do not start if the opposite end, the ICMP retroeflection bag that the bag that sends under the default situations is corresponding can't be given calling process, through using connect, is returned to the process at their place by the asynchronous mistake of the UDP socket initiation that has connected; 3) do not need to break off again earlier between two packets of transmission to connect, promoted efficiency of transmission.
To announcement of the present invention,, do not break away from guidance of the present invention and scope according to above-mentioned, the present invention is made various changes and variation is obviously for those skilled in the art.Therefore, the present invention attempts to be included in various variations and the hardware in the equivalence techniques scope of the present invention, the change of software, and embodiment provided by the invention can realize through hardware, software.
Above-described embodiment; The object of the invention, technical scheme and beneficial effect have been carried out further explain, and institute it should be understood that the above is merely embodiment of the present invention; And be not used in qualification protection scope of the present invention; All within spirit of the present invention and principle, any modification of being made, be equal to replacement, improvement etc., all should be included within protection scope of the present invention.