CN105553977B - Processing, sending method and the device of request message - Google Patents
Processing, sending method and the device of request message Download PDFInfo
- Publication number
- CN105553977B CN105553977B CN201510931931.8A CN201510931931A CN105553977B CN 105553977 B CN105553977 B CN 105553977B CN 201510931931 A CN201510931931 A CN 201510931931A CN 105553977 B CN105553977 B CN 105553977B
- Authority
- CN
- China
- Prior art keywords
- socket
- interim
- udp
- udp socket
- client
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L69/00—Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
- H04L69/16—Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
- H04L69/161—Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields
- H04L69/162—Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields involving adaptations of sockets based mechanisms
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/10—Protocols in which an application is distributed across nodes in the network
- H04L67/104—Peer-to-peer [P2P] networks
- H04L67/1074—Peer-to-peer [P2P] networks for supporting data block transmission mechanisms
- H04L67/1078—Resource delivery mechanisms
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/50—Network services
- H04L67/56—Provisioning of proxy services
- H04L67/568—Storing data temporarily at an intermediate stage, e.g. caching
Abstract
The invention discloses a kind of processing of request message, sending method and devices.Wherein, this method comprises: creating global UDP socket on the default port of server;The request message that client is sent is monitored using global UDP socket;Request message to listen to creates interim UDP socket, and is communicated by the interim socket of UDP with client.The present invention, which solves, to be lacked a kind of efficient concurrent solution in the related technology and had not only been able to satisfy the distribution requirements of data, but also the technical issues of can break through the limitation of the network port and firewall.
Description
Technical field
The present invention relates to the communications fields, in particular to a kind of processing of request message, sending method and device.
Background technique
User Datagram Protocol (User Datagram Protocol, referred to as UDP), be in transport layer one it is simple
The unreliable protocol of datagram-oriented.Compared to transmission control protocol (Transmission Control Protocol, abbreviation
For TCP), the data transmission of UDP is more efficiently, quickly.Especially in the transmitting scenes such as online game, audio, video, more
Being transmission performance of filling weight and and non-transmitting integrality, so being then more preferably to select using UDP.However, most of UDP
Server program is iteration operation, and server is firstly the need of client's request is waited, next reads client request, then
Client request is handled, finally returns to client's response corresponding with client request, and then wait for the client of next arrival
Request.In the case where the treatment process needs of wherein client's request consumed long-time, will seriously hinder to subsequent
Arrival client request handle, thus, in current research process, it is expected that UDP server program can have it is specific
The concurrency of form.
In the related art, it may include following two categories that UDP realization, which is concurrently divided according to the quantity of listening port:
The first kind, server monitor a port
In this approach, server needs to create a socket (socket), bind it to one it is well-known
Port on, total data receive request require to realize by this port with data sending request.Server is from this port
After receiving data, then by particular dispensed strategy by data distribution into application layer program.Common data distribution strategy can
To include but is not limited to: circulating, multi-thread formula, Circular buffer and circle queue formula.
(1) circulating: server handles the request after receiving the request from client, then will ask with this
It asks corresponding response feedback to client, is then further continued for handling next request.
(2) multi-thread formula: server creates a data processing sub thread after receiving the request from client
The data received are individually handled, and processing result is fed back into client, then data processing threads exit.
(3) Circular buffer and circle queue formula: circle queue is created in data receiver thread, for storing number to be returned
According to client identification (such as: the network protocol (IP) of client and port), and create and send in data processing sub thread
Circular buffer and receive Circular buffer, for receiving data with store data to be sent;Data receiver thread receives data simultaneously
Check in circle queue whether the client identification of returned data in need, if so, then corresponding data processing sub thread meeting
Data in Circular buffer are sent.Cyclic buffer in such mode can provide the visit of the mutual exclusion to buffer area
It asks, thus does not need increase mutual exclusion protection between data receiver thread and data processing sub thread to carry out simultaneously, to have
Standby good concurrency performance, cyclic buffer can preferably utilize system memory resource.
However, still having following obvious shortcoming using the solution that server monitors a port:
All data are required to that the distribution of data will necessarily be related to by a socket to receive.Circulating is a kind of
Serial processing mode, does not accomplish concurrency substantially.The request long for processing holding time of this mode, efficiency
Under relatively low.Such as: it is circulating to be required when handling each request for quite a long time in file delivery service,
Thus will lead to subsequent request cannot be handled in time.The creation and destruction of multi-thread formula middle line journey take a long time, because
One thread of creation requires to obtain memory and system resource every time, while also needing to consider to visit the mutual exclusion of data between thread
It asks, so an important technical for improving service routine efficiency is exactly to reduce the number of creation and destroying threads as far as possible,
Current way is to manage thread using thread pool.Though in addition, Circular buffer and circle queue receive the mode of processing data
It is so able to solve the exclusive reference of data between thread, improves concurrency performance, but in fact, Circular buffer and circle queue formula
The fact that be that data distribution mode is different from first two mode, can not change through a socket come sending and receiving data.Such as
Fruit concurrent request amount is huge, and the bottleneck of whole system is just concentrated in data distribution.
Second class, server monitor multiple ports
Server creates a socket (socket) on a well-known port, monitors client's request.Work as clothes
When business device is received from the request of client, its IP address and port are recorded, then requests one son of creation for the client
Thread is responsible for the communication between the client by sub thread.Sub thread creates a new socket, binds on it
(bind) transient port sends all responses to this request by this socket.
Although only being monitored in a port in data set however, being able to solve in such a way that server monitors multiple ports
The problem of distribution, still equally exists following obvious shortcoming using the solution that server monitors multiple ports:
(1) under normal circumstances, the firewall of server end can only allow data by specific port, without opening
All ports, to prevent server by malicious attack.Thus will lead to data can not break through the limitation of firewall.And
Even if the not limitation of firewall, if client is specified to receive data from server Single port, client's termination will also result in
Receive data failure.
(2) request sent for each client, server require one new port of distribution, since port provides
Source is limited (at most only 65535), accordingly even when server performance is good again, processing routine is efficient again, in server
In the case where an IP address, the total number of concurrent request by be difficult to break through 65535 the limit.
For above-mentioned problem, currently no effective solution has been proposed.
Summary of the invention
The embodiment of the invention provides a kind of processing of request message, sending method and devices, at least to solve related skill
Lack a kind of efficient concurrent solution in art and be not only able to satisfy the distribution requirements of data, but also the network port and anti-can be broken through
The technical issues of limitation of wall with flues.
According to an aspect of an embodiment of the present invention, a kind of processing method of request message is provided, comprising: in server
Default port on create global UDP socket;The request message that client is sent is monitored using global UDP socket;For prison
The request message heard creates interim UDP socket, and is communicated by the interim socket of UDP with client.
Further, monitoring the request message that client is sent using global UDP socket includes: to be socketed global UDP
Socket option in word is positioned to allow for interim UDP socket and global UDP socket is tied to the mark of server simultaneously
Information, and the identification information of server and global UDP socket are bound;It is recycled and is monitored using global UDP socket
Request message is waited, and when request message reaches server, creates sub thread or process handles request message.
Further, interim UDP socket is created for request message, and is communicated by interim socket with client
It include: interim UDP socket to be created in sub thread or process, and allow interim UDP socket to the identification information of server
It is multiplexed;The first system function is called to bind the identification information of server and interim UDP socket;Call the second system
System function binds the identification information of client and interim UDP socket;It is sent by interim UDP socket to client
Data and/or the data received by the reading of interim UDP socket from client.
Further, reading the data received from client by interim UDP socket includes: to obtain and default port
The interim UDP socket of the whole to match, and matching is chosen according to the identification information of server and/or the identification information of client
The highest interim UDP socket of degree is as interim UDP socket;Interim UDP socket generate read signal, and from face
When UDP socket associated receive the data that receive from client are read in buffer area.
According to another aspect of an embodiment of the present invention, a kind of sending method of request message is additionally provided, comprising: in client
UDP socket is created on end, and the identification information of server is bound with UDP socket;By UDP socket to service
Device sends request message.
Further, after sending request message to server by UDP socket, further includes: calling system function
The response data corresponding with request message received from server is read from UDP socket.
Another aspect according to an embodiment of the present invention, additionally provides a kind of processing unit of request message, comprising: creation mould
Block, for creating global UDP socket on the default port of server;Module is monitored, for using global UDP socket prison
The request message for listening client to send;Communication module for the interim UDP socket of request message creation to listen to, and is led to
The interim socket of UDP is crossed to be communicated with client.
Further, monitoring module includes: the first creating unit, for creating global UDP socket on default port,
Wherein, global UDP socket is for monitoring request message;First processing units, for by the socket in global UDP socket
Option is positioned to allow for interim UDP socket and global UDP socket is tied to the identification information of server simultaneously, and will clothes
The identification information of business device and global UDP socket are bound;Monitoring unit, for being monitored using global UDP socket circulation
Request message is waited, and when request message reaches server, creates sub thread or process handles request message.
Further, communication module includes: the second processing unit, for creating interim UDP set in sub thread or process
Word is connect, and interim UDP socket is allowed to be multiplexed the identification information of server;First binding unit, for calling first
System function binds the identification information of server and interim UDP socket;Second binding unit, for calling the second system
System function binds the identification information of client and interim UDP socket;Communication unit, for being socketed by interim UDP
Word sends data to client and/or reads the data received from client by interim UDP socket.
Further, communication unit includes: coupling subelement, interim for obtaining the whole to match with default port
UDP socket, and it is highest interim according to the identification information of server and/or the identification information of client selection matching degree
UDP socket is as interim UDP socket;Reading subunit, for interim UDP socket generate read signal, and from
Interim UDP socket is associated to receive the data for reading in buffer area and receiving from client.
It is according to an embodiment of the present invention in another aspect, additionally providing a kind of sending device of request message, comprising: processing mould
Block is bound for creating UDP socket on the client, and by the identification information of server with UDP socket;Send mould
Block, for sending request message to server by UDP socket.
Further, above-mentioned apparatus further include: read module is read from UDP socket from clothes for calling system function
The response data corresponding with request message that business device receives.
In embodiments of the present invention, visitor is listened to using the global UDP socket created on the default port of server
The request message that family end is sent;Interim UDP socket is created for request message, and by the identification information and client of server
Identification information and this UDP socket bind, and communicated by the interim socket of UDP with client, by using complete
Office's UDP socket listens to the request message of client transmission on default port, and asking of sending of respectively each client
It asks message that an interim UDP socket is respectively created, has reached system kernel rank using the function that system kernel function provides
Concurrent processing purpose, disappear to realize and only need to monitor the request that each client is sent on a default port
Breath, without distributing a port for each interim socket, in addition, firewall only needs to open default port
It puts, while also breaching the technical effect in the quantity of the request message of same time access services device, and then solve correlation
Lack a kind of efficient concurrent solution in technology and be not only able to satisfy the distribution requirements of data, but can break through the network port and
The technical issues of limitation of firewall.
Detailed description of the invention
The drawings described herein are used to provide a further understanding of the present invention, constitutes part of this application, this hair
Bright illustrative embodiments and their description are used to explain the present invention, and are not constituted improper limitations of the present invention.In the accompanying drawings:
Fig. 1 is the flow chart of the processing method of request message according to an embodiment of the present invention;
Fig. 2 is that independently operated UDP concurrent server according to the preferred embodiment of the invention and client carry out communication friendship
Mutual schematic diagram;
Fig. 3 is the client's request according to the preferred embodiment of the invention received in server end concurrent processing from client
Flow chart;
Fig. 4 is the flow chart of the sending method of request message according to an embodiment of the present invention;
Fig. 5 is the flow chart according to the preferred embodiment of the invention that client's request is sent from client;
Fig. 6 is the structural block diagram of the processing unit of request message according to an embodiment of the present invention;
Fig. 7 is the structural block diagram of the processing unit of request message according to the preferred embodiment of the invention;
Fig. 8 is the structural block diagram of the sending device of request message according to an embodiment of the present invention;
Fig. 9 is the structural block diagram of the sending device of request message according to an embodiment of the present invention.
Specific embodiment
In order to enable those skilled in the art to better understand the solution of the present invention, below in conjunction in the embodiment of the present invention
Attached drawing, technical scheme in the embodiment of the invention is clearly and completely described, it is clear that described embodiment is only
The embodiment of a part of the invention, instead of all the embodiments.Based on the embodiments of the present invention, ordinary skill people
The model that the present invention protects all should belong in member's every other embodiment obtained without making creative work
It encloses.
It should be noted that description and claims of this specification and term " first " in above-mentioned attached drawing, "
Two " etc. be to be used to distinguish similar objects, without being used to describe a particular order or precedence order.It should be understood that using in this way
Data be interchangeable under appropriate circumstances, so as to the embodiment of the present invention described herein can in addition to illustrating herein or
Sequence other than those of description is implemented.In addition, term " includes " and " having " and their any deformation, it is intended that cover
Cover it is non-exclusive include, for example, the process, method, system, product or equipment for containing a series of steps or units are not necessarily limited to
Step or unit those of is clearly listed, but may include be not clearly listed or for these process, methods, product
Or other step or units that equipment is intrinsic.
According to embodiments of the present invention, a kind of embodiment of the method for the processing method of request message is provided, needs to illustrate
It is that step shown in the flowchart of the accompanying drawings can execute in a computer system such as a set of computer executable instructions,
Also, although logical order is shown in flow charts, and it in some cases, can be to be different from sequence execution herein
Shown or described step.
Fig. 1 is the flow chart of the processing method of request message according to an embodiment of the present invention, as shown in Figure 1, this method packet
Include following steps:
Step S102 creates global UDP socket on the default port of server;
Step S104 monitors the request message that client is sent using global UDP socket;
Step S106, the request message to listen to creates interim UDP socket, and passes through the interim socket of UDP and visitor
Family end is communicated.
Through the above steps, the request that only needs monitor that each client is sent on a default port is realized to disappear
Breath, without distributing a port for each interim socket, in addition, firewall only needs to open default port
It puts, while also breaching the technical effect in the quantity of the request message of same time access services device, and then solve correlation
Lack a kind of efficient concurrent solution in technology and be not only able to satisfy the distribution requirements of data, but can break through the network port and
The technical issues of limitation of firewall.
One socket socket is determined by five-tuple, i.e. P=(P1 agreement, P2 source IP address: source port, P3 mesh
IP address: destination port), due to being directed to the concurrent scheme of UDP in the technical solution provided by the present invention,
Above-mentioned agreement P1 is UDP.
Optionally, in step S104, monitoring the request message that client is sent using global UDP socket may include
Following steps:
Step S1: by global UDP socket socket option (such as: SO_REUSEADDR) be positioned to allow for it is interim
UDP socket and global UDP socket are tied to the identification information of server (including but not limited to: the IP of server simultaneously
The port numbers of location and server), and the identification information of server and global UDP socket are bound;
Step S2: it is monitored using global UDP socket circulation and waits request message, and reach server in request message
When, it creates sub thread or process handles request message.
Optionally, in step s 106, interim UDP socket is created for request message, and passes through interim socket and visitor
It may include following operation that family end, which carries out communication:
Step S3: creating interim UDP socket in sub thread or process, and allows interim UDP socket to server
Identification information be multiplexed;
Step S4: the first system function is called to bind the identification information of server and interim UDP socket;
Step S5: call second system function by the identification information of client (including but not limited to: the IP address of client
With the port numbers of client) it is bound with interim UDP socket;
Step S6: by interim UDP socket to client send data and/or by interim UDP socket reading from
The data that client receives.
In a preferred embodiment, Fig. 2 is independently operated UDP concurrent server according to the preferred embodiment of the invention and visitor
The schematic diagram of family end progress communication interaction.As shown in Fig. 2, server is created on a well known port (i.e. above-mentioned default port)
The reusable scoket socket in an address is built, is responsible for monitoring client connection request.When monitor socket on receive visitor
When family end is requested, client requests the creation reusable socket socket in one new address thus, and thus socket is responsible for it
Remaining needs are communicated with the service logic that client carries out.Specifically, it can use system function function (i.e. above-mentioned the first system
Function) bind (int bind (int sockfd, const struct sockaddr*myaddr, sock len_t
addrlen);) be tied to the IP address of local server and port numbers on newly-built socket, then reutilization system function
Function (i.e. above-mentioned second system function) connect (int connect (int sockfd, const struct sockaddr*
servaddr,socklen_t addrlen);) IP address of client and port numbers are also tied on newly-built socket.
In this way, server end can be responsible for the issued transaction between client on newly created socket, and monitor socket
It is then merely responsible for monitoring the request message that client is sent.Thus, it is only necessary to a port is monitored in server end, it can be in kernel
Disperse the flow of request message in rank to each corresponding interim UDP socket.Meanwhile firewall only needs to open this
Well-known port, without distributing a port for each interim socket, in addition, be capable of the request message of concurrent processing
Maximum quantity can also break through 65535 limitation.
One native protocol address can be assigned a socket by bind function (i.e. above-mentioned the first system function), and
The network transmission layer address of one local is got up with sockets associated.For UDP, that is, by five yuan of scoket socket
Group P in P2 part (source IP address: source port) be appointed as local IP address and port, can be shown as in kernel by
It is bound on local IP and local port in the udp protocol control block (PCB) of this socket sockets associated.Process can
With by specific an IP address and Port BindingBundling to socket, but this IP address must belong to it where the network of host connect
One of mouthful.For UDP client, just the IP datagram to send on the socket assigns source IP address and port.
For UDP server end, which define the clients that the socket only receives those destinations IP address and port thus
Connection.Bind function is called to can specify IP address and/or port, naturally it is also possible to not specified IP address and/or port.
It is the specified IP address and/or port numbers for needing to bundle of bind function that table 1, which shows the preferred embodiment of the present invention,
The result of generation.As shown in table 1,
Table 1
The value how source IP and source port are set according to expected result is summarized in above table.If designated ends slogan
It is 0, then kernel just selects a transient port when bind is called;If specified IP address is wildcard address, needle
For TCP, kernel will have connected until socket, alternatively, kernel issues datagram on socket for UDP
When just select a local ip address.
Connect function (i.e. above-mentioned second system function) can be applied in UDP socket, the difference with TCP connection
It is: without three-way handshake.Only record external address is i.e. by the udp protocol control block (PCB) of this socket sockets associated
In external IP and outside port on specified, use when to send datagram on this socket, that is, by this
The part P3 (purpose IP address: destination port) in scoket socket five-tuple P is determined.It is then immediately returned to call
Process, thus just can ensure datagram only can be passed to the socket socket of IP specified by connect function and port
On word.
It should be noted that newly creation UDP socket is defaulted as not connected UDP socket, it to be made to become to have connected UDP
Socket needs to call it connect system function.
UDP socket is had connected compared with the not connected UDP socket of default, difference essentially consists in following three points:
(1) specified purpose IP address and port numbers cannot be operated for output.It has write any interior in connection UDP socket
Hold the protocol address (such as: IP address and port numbers) for being all sent automatically to be specified by connect.
(2) sender of datagram need not be learned using recvfrom function, and use instead read function, recv function or
Recvmsg function.It is had connected in UDP socket at one, is that the datagram that input operation returns only has those to come from by kernel
The datagram of protocol address specified by connect.Destination be this have connected UDP socket native protocol (such as: IP
Location and port numbers), and source address is not the datagram for the protocol address that the previous connect of the socket is arrived, and will not be transmitted
To the socket.Thus one can be limited to have connected UDP socket energy and be only capable of and an opposite end exchange datagrams.
(3) as the process where the asynchronous error for having connected UDP socket initiation can return to them, and be not connected with
UDP socket does not receive any asynchronous error.
So far, it is called by bind system and connect system is called, by this scoket socket five-tuple P
In 3 parts (P1 agreement, P2 source IP address: source port, P3 purpose IP address: destination port) determined, so just
Can one socket socket of unique identification, be routed to specific socket for datagram and provide technical support.
Optionally, in step s 6, by interim UDP socket read the data that are received from client may include with
Lower step:
Step S61: the interim UDP socket of whole to match with default port is obtained, and is believed according to the mark of server
Breath and/or the identification information of client choose the highest interim UDP socket of matching degree as above-mentioned interim UDP socket;
Step S62: generating in interim UDP socket and read signal, and delays from receive associated with interim UDP socket
Rush the data that reading is received from client in area.
In a preferred embodiment, the data that server end is sent in interim UDP socket can be routed automatically to by kernel
On port where client;And the data of server are sent to from client, and after received server-side to above-mentioned data, meeting
The associated reception buffer area of interim UDP socket descriptor is routed automatically to by kernel protocol stack, and in interim UDP socket
It generates and reads signal.
When UDP datagram enters ICP/IP protocol stack, the treatment process of kernel is as follows:
The input function UDP_INPUT that datagram can be passed to corresponding UDP by IP layers is handled, UDP_INPUT's
Target is placed into UDP datagram in the caching of suitable socket, is waken up on the socket because of the calling (example of input obstruction
Such as: select).UDP_INPUT passes through (source IP address: source port, purpose IP address: destination port) and UDP to datagram
In (local ip address: local port, outside ip address: outside port) of all socket sockets associateds matched.And
The rule that UDP message consigns to corresponding socket socket is as follows:
(1) UDP datagram by destination for Broadcast IP address or Multicast IP Address consigns to all matched sockets;
(2) the arrival UDP datagram that destination is unicast ip address is only consigned into a matched socket, that is, had most
The socket of small wildcard coupling number.If there is multiple sockets " minimum " wildcard coupling number having the same, then specifically by which
Socket then depends on different applicable scenes to receive arrival datagram.
(3) usually connect system is called and is associated, still, UDP client or UDP server with TCP Client
Connect function may also be called, is socket designated external IP address and outer end slogan.It is necessary which limits socket
Only UDP datagram is exchanged with some specific other side.
Table 2 shows the local of UDP socket and outside ip address and port specification in the preferred embodiment of the present invention.Such as table 2
It is shown,
Table 2
Three kinds of different states and function that UDP scoket is presented in above table are to terminate each state to call
Pseudocode, " * .lport " indicate that local IP is default and " * .* " indicates that external IP and outside port are default.In preferred embodiment
Used in monitoring socket be that (the third line in above table, that is, be limited on this interface for second of state in table 2
The datagram of arrival), it thus can receive all users and request connection.And after receiving request connection, newly-built set
Word is connect after bind system is called and connect system is called, the first state (the in above table will be converted into
Two rows are restricted to an other side).
In a preferred implementation process, the highest interim UDP of matching degree can be chosen according to minimum wildcard coupling number principle
Socket is as above-mentioned interim UDP socket.Minimum wildcard coupling number principle, which refers to UDP message message only, can be transmitted to most
On the small matched socket of wildcard.
Table 3 show the preferred embodiment of the present invention local port be 23 three UDP sockets.As shown in table 3,
Table 3
Local address | Local port | External address | Outside port |
140.252.1.29 | 23 | * | * |
* | 23 | * | * |
140.252.1.29 | 23 | 140.252.1.11 | 1500 |
In above table, three sockets on a host, " * " indicates default.When UDP receives a destination port
For 23 message segment when, call kernel function, search for entire Internet PCB table (referring herein to Internet PCB table be
A transport layer list structure in kernel protocol stack, each single item in chained list are a protocol control block (PCB), protocol control block
It is used to store the shared information of all UDP leafs: external and local ip address, outside and local port, IP stem prototype etc.
Other related contents.Because UDP be it is connectionless, a leaf need all information may be stored in Internet
In PCB) find a matched PCB node.In order to determine wildcard coupling number, only consider in the preferred embodiment local and outer
The IP address in portion puts aside outer end slogan.Local port number is to have to matched, and otherwise datagram can not route at all
Onto application program.Wildcard coupling number can be 0,1 (local ip address or outside ip address), 2 (local and outside ip address).
Table 4 shows from { 140.252.1.11,1500 } to { 140.252.1.29,23 } of the preferred embodiment of the present invention
Reach message segment.As shown in table 4,
Table 4
Local address | Local port | External address | Outside port | Wildcard coupling number |
140.252.1.29 | 23 | * | * | 1 |
* | 23 | * | * | 2 |
140.252.1.29 | 23 | 140.252.1.11 | 1500 | 0 |
For example it is assumed that reaching message segment comes from 140.252.1.11, port 1500, destination is 140.252.1.29, end
Mouth 23, " * " indicate default.When compared with the second row in above table, external address wildcard is matched, and wildcard coupling number is
1;When compared with the third line in above table, local address and the matching of external address wildcard, wildcard coupling number is 2;When
When compared with the last line in above table, discovery local address, external address and outside port exact matching, wildcard
Coupling number is 0.Using the matched principle of minimum wildcard, this message segment can be transmitted to socket interface corresponding to last line
On, thus revealing client and being sent to the data of server can correctly be delivered on the socket socket associated by it
Technical principle.
Above-mentioned preferred implementation process is further described below in conjunction with preferred embodiment shown in Fig. 3.
Fig. 3 is the client's request according to the preferred embodiment of the invention received in server end concurrent processing from client
Flow chart.As shown in figure 3, the process may include following processing step:
Step S302, server end can create a UDP and monitor socket, wherein the UDP monitors socket for supervising
The connection request for listening client to send.
Step S304, server end is repeated to bundle completely and be allowed subsequent using system function setsockopt to allowing
Newly-built socket (socket), which can be bundled on identical server address, to be configured.
Step S306, server end monitors local ip address and port binding on socket to UDP.
Step S308-S310, server end waits the connection request of client in the circulating cycle, whenever request reaches server
When, server end handles the connection request of client transmission by a sub thread or process is created.
Step S312, server end creates a socket in sub thread or process for the connection request of client
(socket)。
Step S314, server end can reuse original binding to newly-built socket using system function setsockopt
Address be configured.
Step S316, the IP address of local server and port are tied to by server end respectively using system function bind
On the local IP and local port for including in newly-built socket (socket) associated udp protocol.
Step S318, server end is tied up the IP address of requesting client and port using system function connect respectively
In the fixed external IP and outside port for including into newly-built socket (socket) associated udp protocol.
Step S320, the server program in server end can be carried out on above-mentioned newly-built socket (socket) with
TCP similar read-write operation carries out the affair logic processing.
Step S322, after server-side processes, socket is closed.
It should be noted that SO_REUSEADDR can be arranged to socket socket option has allowed for UDP
Complete duplicate binding: when an IP address and port have been tied in particular socket, same IP address and port may be used also
To be bundled on another socket.Moreover, if allowing duplicate binding completely, with also needing to bundle the same IP
SO_REUSEADDR option is positioned to allow for completely duplicate binding by each socket of location and port could be complete.Upper
It states in step S306 and step S316 due to being all bundled with identical server ip address and well-known port, therefore, it is necessary to be arranged
SO_REUSEADD option is to allow duplicate binding completely.
Fig. 4 is the flow chart of the sending method of request message according to an embodiment of the present invention.As shown in Figure 1, this method can
To include following processing step:
Step S402, UDP socket is created on the client, and the identification information of server and UDP socket are carried out
Binding;
Step S404, request message is sent to server by interim UDP socket.
Optionally, it can also be wrapped after sending request message to server by interim UDP socket in step S404
Include following steps:
Step S7: calling system function receives from the reading of interim UDP socket from server corresponding with request message
Response data.
In a preferred embodiment, Fig. 5 is according to the preferred embodiment of the invention from client transmission client
The flow chart of request.As shown in figure 5, the process may include following processing step:
Step S502, client creates a UDP socket socket.
Step S504, the IP address of server end and port are tied to by client respectively using system function connect
In the external IP and outside port for including in the udp protocol of newly-built socket sockets associated, it is socketed in this way in this socket
Data are sent on word not need to specify purpose IP address and port every time.
Step S506-S508, client sends a connection request on this socket socket, then in this socket
It is upper to carry out the read-write operation similar with TCP, carry out the affair logic processing.
Step S510, client judges whether affairs are completed;If it is not, then return step S506;If it is, continuing to hold
Row step S512.
Step S512, client closes socket socket.
Fig. 6 is the structural block diagram of the processing unit of request message according to an embodiment of the present invention.As shown in fig. 6, the request
The processing unit of message may include: creation module 10, for creating global UDP socket on the default port of server;
Module 20 is monitored, for monitoring the request message that client is sent using global UDP socket;Communication module 30, for being prison
The request message heard creates interim UDP socket, and is communicated by the interim socket of UDP with client.
Optionally, Fig. 7 is the structural block diagram of the processing unit of request message according to the preferred embodiment of the invention.Such as Fig. 7
Shown, monitoring module 20 may include: first processing units 200, for the socket option in global UDP socket to be arranged
To allow interim UDP socket and global UDP socket to be tied to the identification information of server simultaneously, and by the mark of server
Know information to be bound with global UDP socket;Monitoring unit 202 is asked for monitoring to wait using global UDP socket circulation
Message is sought, and when request message reaches server, creates sub thread or process handles request message.
Optionally, as shown in fig. 7, communication module 30 may include: the second processing unit 300, for sub thread or into
Interim UDP socket is created in journey, and interim UDP socket is allowed to be multiplexed the identification information of server;First binding
Unit 302, for calling the first system function to bind the identification information of server and interim UDP socket;Second ties up
Order member 304, for calling second system function to bind the identification information of client and interim UDP socket;Communication
Unit 306, for sending data to client by interim UDP socket and/or being read by interim UDP socket from client
Terminate the data received.
Optionally, communication unit 306 may include: coupling subelement (not shown), for obtaining and default port
The interim UDP socket of the whole to match, and matching is chosen according to the identification information of server and/or the identification information of client
The highest interim UDP socket of degree is as above-mentioned interim UDP socket;Reading subunit (not shown), for facing
When UDP socket generate read signal, and from receptions buffer area associated with interim UDP socket read from client termination
The data received.
Fig. 8 is the structural block diagram of the sending device of request message according to an embodiment of the present invention.As shown in figure 8, the request
The sending device of message may include: processing module 40, for creating UDP socket on the client, and by the mark of server
Know information to be bound with UDP socket;Sending module 50, for sending request message to server by UDP socket.
Optionally, Fig. 9 is the structural block diagram of the sending device of request message according to an embodiment of the present invention.As shown in figure 9,
Above-mentioned apparatus can also include: read module 60, receive from UDP socket reading from server for calling system function
Response data corresponding with request message.
The serial number of the above embodiments of the invention is only for description, does not represent the advantages or disadvantages of the embodiments.
In the above embodiment of the invention, it all emphasizes particularly on different fields to the description of each embodiment, does not have in some embodiment
The part of detailed description, reference can be made to the related descriptions of other embodiments.
In several embodiments provided herein, it should be understood that disclosed technology contents can pass through others
Mode is realized.Wherein, the apparatus embodiments described above are merely exemplary, such as the division of the unit, Ke Yiwei
A kind of logical function partition, there may be another division manner in actual implementation, for example, multiple units or components can combine or
Person is desirably integrated into another system, or some features can be ignored or not executed.Another point, shown or discussed is mutual
Between coupling, direct-coupling or communication connection can be through some interfaces, the INDIRECT COUPLING or communication link of unit or module
It connects, can be electrical or other forms.
The unit as illustrated by the separation member may or may not be physically separated, aobvious as unit
The component shown may or may not be physical unit, it can and it is in one place, or may be distributed over multiple
On unit.It can some or all of the units may be selected to achieve the purpose of the solution of this embodiment according to the actual needs.
It, can also be in addition, the functional units in various embodiments of the present invention may be integrated into one processing unit
It is that each unit physically exists alone, can also be integrated in one unit with two or more units.Above-mentioned integrated list
Member both can take the form of hardware realization, can also realize in the form of software functional units.
If the integrated unit is realized in the form of SFU software functional unit and sells or use as independent product
When, it can store in a computer readable storage medium.Based on this understanding, technical solution of the present invention is substantially
The all or part of the part that contributes to existing technology or the technical solution can be in the form of software products in other words
It embodies, which is stored in a storage medium, including some instructions are used so that a computer
Equipment (can for personal computer, server or network equipment etc.) execute each embodiment the method for the present invention whole or
Part steps.And storage medium above-mentioned includes: that USB flash disk, read-only memory (ROM, Read-Only Memory), arbitrary access are deposited
Reservoir (RAM, Random Access Memory), mobile hard disk, magnetic or disk etc. be various to can store program code
Medium.
The above is only a preferred embodiment of the present invention, it is noted that for the ordinary skill people of the art
For member, various improvements and modifications may be made without departing from the principle of the present invention, these improvements and modifications are also answered
It is considered as protection scope of the present invention.
Claims (8)
1. a kind of processing method of request message characterized by comprising
Global User Datagram Protocol UDP socket is created on the default port of server;
The request message that client is sent is monitored using the global UDP socket;
The request message to listen to creates interim UDP socket, and passes through the interim socket of the UDP and the client
End is communicated.
2. the method according to claim 1, wherein monitoring the client using the global UDP socket
Send the request message include:
Socket option in the global UDP socket is positioned to allow for the interim UDP socket and the overall situation UDP
Socket is tied to the identification information of the server simultaneously, and by the identification information of the server and the overall situation UDP
Socket is bound;
It is monitored using the global UDP socket circulation and waits the request message, and reach the clothes in the request message
When business device, creates sub thread or process handles the request message.
3. according to the method described in claim 2, it is characterized in that, create the interim UDP socket for the request message,
And communicate with the client by the interim socket include:
The interim UDP socket is created in sub thread or process, and allows the interim UDP socket to the server
Identification information be multiplexed;
The first system function is called to bind the identification information of the server and the interim UDP socket;
Second system function is called to bind the identification information of the client and the interim UDP socket;
By the interim UDP socket to the client send data and/or by the interim UDP socket reading from
The data that the client receives.
4. according to the method described in claim 3, it is characterized in that, being read by the interim UDP socket from the client
Terminating the data received includes:
Obtain the interim UDP socket of whole to match with the default port, and according to the identification information of the server and/
Or the identification information of the client chooses the highest interim UDP socket of matching degree as the interim UDP socket;
It is generated in the interim UDP socket and reads signal, and from reception buffer area associated with the interim UDP socket
It is middle to read the data received from the client.
5. a kind of processing unit of request message characterized by comprising
Creation module, for creating global User Datagram Protocol UDP socket on the default port of server;
Module is monitored, for monitoring the request message that client is sent using the global UDP socket;
Communication module for the interim UDP socket of request message creation to listen to, and is temporarily covered by the UDP
Word is connect to be communicated with the client.
6. device according to claim 5, which is characterized in that the monitoring module includes:
First creating unit, for creating the global UDP socket on the default port, wherein the overall situation UDP set
Word is connect for monitoring the request message;
First processing units are covered for the socket option in the global UDP socket to be positioned to allow for the interim UDP
It connects word and the global UDP socket is tied to the identification information of the server simultaneously, and by the mark of the server
Information is bound with the global UDP socket;
Monitoring unit is waited the request message for being monitored using the global UDP socket circulation, and disappeared in the request
When breath reaches the server, creates sub thread or process handles the request message.
7. device according to claim 6, which is characterized in that the communication module includes:
The second processing unit for creating the interim UDP socket in sub thread or process, and allows the interim UDP
Socket is multiplexed the identification information of the server;
First binding unit, for calling the first system function to be socketed the identification information of the server and the interim UDP
Word is bound;
Second binding unit, for calling second system function to be socketed the identification information of the client and the interim UDP
Word is bound;
Communication unit, for sending data to the client by the interim UDP socket and/or by described interim
UDP socket reads the data received from the client.
8. device according to claim 7, which is characterized in that the communication unit includes:
Coupling subelement, for obtaining the interim UDP socket of whole to match with the default port, and according to the service
The identification information of device and/or the identification information of the client are chosen described in the highest interim UDP socket conduct of matching degree
Interim UDP socket;
Reading subunit reads signal for generating in the interim UDP socket, and from the interim UDP socket phase
The data received from the client are read in associated reception buffer area.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201510931931.8A CN105553977B (en) | 2015-12-15 | 2015-12-15 | Processing, sending method and the device of request message |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201510931931.8A CN105553977B (en) | 2015-12-15 | 2015-12-15 | Processing, sending method and the device of request message |
Publications (2)
Publication Number | Publication Date |
---|---|
CN105553977A CN105553977A (en) | 2016-05-04 |
CN105553977B true CN105553977B (en) | 2019-05-24 |
Family
ID=55832913
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201510931931.8A Active CN105553977B (en) | 2015-12-15 | 2015-12-15 | Processing, sending method and the device of request message |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN105553977B (en) |
Families Citing this family (14)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106131112A (en) * | 2016-06-14 | 2016-11-16 | 上海电气集团股份有限公司 | A kind of rehabilitation training apparatus monitoring method and rehabilitation training of upper limbs equipment |
CN106131180A (en) * | 2016-07-08 | 2016-11-16 | 深圳市沃特沃德股份有限公司 | The processing method of the many concurrent requests of intelligent terminal, Apparatus and system |
CN106790022B (en) * | 2016-12-14 | 2019-06-18 | 福建天泉教育科技有限公司 | Communication means and its system based on more inquiry threads |
CN107132799A (en) * | 2017-06-21 | 2017-09-05 | 湖南利能科技股份有限公司 | A kind of apparatus and method of many MCU data interactions intelligent acquisitions |
CN109474661B (en) * | 2018-09-25 | 2021-05-14 | 视联动力信息技术股份有限公司 | Method and system for processing network request event |
CN111511041B (en) * | 2019-01-31 | 2022-03-29 | 大唐移动通信设备有限公司 | Remote connection method and device |
CN110011967A (en) * | 2019-02-27 | 2019-07-12 | 新奥特(北京)视频技术有限公司 | A kind of method and system for data transmission |
CN110166479B (en) * | 2019-05-31 | 2022-02-01 | 深圳市瑞云科技有限公司 | Method for improving UDP (user Datagram protocol) sending efficiency of transmission system |
CN113726723B (en) * | 2020-05-26 | 2023-11-03 | 杭州萤石软件有限公司 | UDP-based data transmission method, device and equipment |
CN112492054A (en) * | 2020-11-05 | 2021-03-12 | 杭州萤石软件有限公司 | Multiplexing method, device and equipment for UDP (user Datagram protocol) port |
CN112579210A (en) * | 2020-12-30 | 2021-03-30 | 上海众源网络有限公司 | Application program control method and device |
CN113162932B (en) * | 2021-04-23 | 2023-01-06 | 航天新通科技有限公司 | Asynchronous I/O operation method and device based on socket |
CN114244758A (en) * | 2021-12-13 | 2022-03-25 | 武汉斗鱼鱼乐网络科技有限公司 | Network diagnosis method, storage medium, electronic device and system of android platform |
CN114938395A (en) * | 2022-05-11 | 2022-08-23 | 北京字节跳动网络技术有限公司 | Service response method, device, equipment and storage medium |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102624651A (en) * | 2012-03-08 | 2012-08-01 | 北京神州数码思特奇信息技术股份有限公司 | Gateway communication method and device |
CN103763156A (en) * | 2014-01-28 | 2014-04-30 | 中国移动(深圳)有限公司 | Network speed measurement method and system |
Family Cites Families (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103117895B (en) * | 2013-01-25 | 2016-01-13 | 哈尔滨工业大学 | A kind of services listen method of LXI instrument |
CN104410982B (en) * | 2014-11-19 | 2017-11-14 | 南京邮电大学 | Terminal polymerization and reconstructing method in a kind of Wireless Heterogeneous Networks |
-
2015
- 2015-12-15 CN CN201510931931.8A patent/CN105553977B/en active Active
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102624651A (en) * | 2012-03-08 | 2012-08-01 | 北京神州数码思特奇信息技术股份有限公司 | Gateway communication method and device |
CN103763156A (en) * | 2014-01-28 | 2014-04-30 | 中国移动(深圳)有限公司 | Network speed measurement method and system |
Also Published As
Publication number | Publication date |
---|---|
CN105553977A (en) | 2016-05-04 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN105553977B (en) | Processing, sending method and the device of request message | |
CN108377671B (en) | Method and computer equipment for processing message | |
CN104184828B (en) | Hybrid network system, communication means and network node | |
Wetherall et al. | Introducing new internet services: Why and how | |
US20040177158A1 (en) | Network address translation techniques for selective network traffic diversion | |
CN1578320B (en) | Network load balancing with main machine status information | |
CN108476208A (en) | Multi-path transmission designs | |
CN106031133A (en) | An anycast based, wide area distributed mapping and load balancing system | |
CN104486589B (en) | Access method and device in video monitoring system based on GVRP | |
CN106209648B (en) | Multicast data packet forwarding method and apparatus across virtual expansible local area network | |
CN103238301A (en) | Technique for managing traffic at router | |
AU2001296185A1 (en) | Configuration of a flexible infrastructure | |
CN106357542B (en) | The method and software defined network controller of multicast service are provided | |
CN108401037A (en) | User terminal and the binding method of equipment, device and system | |
CN109525684A (en) | Message forwarding method and device | |
CN109194525A (en) | A kind of network node configuration method and management node | |
CN108259632A (en) | A kind of CGN implementation methods and device | |
CN107864101A (en) | Load-balancing method and device | |
CN109474713A (en) | Message forwarding method and device | |
CN107508836A (en) | The method and device that a kind of acl rule issues | |
JP4896532B2 (en) | Communication channel model | |
CN103827830B (en) | System and method for preventing "bottleneck" in transactional middleware machine environment | |
CN110460641A (en) | Data transmission method, apparatus and system | |
CN103609063B (en) | The method and apparatus that protocol independent multicast last hop router finds | |
CN104219257B (en) | A kind of webpage real-time communication method, system and server and client side |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |