Movatterモバイル変換


[0]ホーム

URL:


CN105553977B - Processing, sending method and the device of request message - Google Patents

Processing, sending method and the device of request message
Download PDF

Info

Publication number
CN105553977B
CN105553977BCN201510931931.8ACN201510931931ACN105553977BCN 105553977 BCN105553977 BCN 105553977BCN 201510931931 ACN201510931931 ACN 201510931931ACN 105553977 BCN105553977 BCN 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
Application number
CN201510931931.8A
Other languages
Chinese (zh)
Other versions
CN105553977A (en
Inventor
刘光亮
杨俊伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Netease Hangzhou Network Co Ltd
Original Assignee
Netease Hangzhou Network Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Netease Hangzhou Network Co LtdfiledCriticalNetease Hangzhou Network Co Ltd
Priority to CN201510931931.8ApriorityCriticalpatent/CN105553977B/en
Publication of CN105553977ApublicationCriticalpatent/CN105553977A/en
Application grantedgrantedCritical
Publication of CN105553977BpublicationCriticalpatent/CN105553977B/en
Activelegal-statusCriticalCurrent
Anticipated expirationlegal-statusCritical

Links

Classifications

Landscapes

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

Processing, sending method and the device of request message
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 simpleThe unreliable protocol of datagram-oriented.Compared to transmission control protocol (Transmission Control Protocol, abbreviationFor TCP), the data transmission of UDP is more efficiently, quickly.Especially in the transmitting scenes such as online game, audio, video, moreBeing transmission performance of filling weight and and non-transmitting integrality, so being then more preferably to select using UDP.However, most of UDPServer program is iteration operation, and server is firstly the need of client's request is waited, next reads client request, thenClient request is handled, finally returns to client's response corresponding with client request, and then wait for the client of next arrivalRequest.In the case where the treatment process needs of wherein client's request consumed long-time, will seriously hinder to subsequentArrival client request handle, thus, in current research process, it is expected that UDP server program can have it is specificThe 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-knownPort on, total data receive request require to realize by this port with data sending request.Server is from this portAfter receiving data, then by particular dispensed strategy by data distribution into application layer program.Common data distribution strategy canTo 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 thisIt 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 clientThe 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 returnedAccording to client identification (such as: the network protocol (IP) of client and port), and create and send in data processing sub threadCircular buffer and receive Circular buffer, for receiving data with store data to be sent;Data receiver thread receives data simultaneouslyCheck in circle queue whether the client identification of returned data in need, if so, then corresponding data processing sub thread meetingData in Circular buffer are sent.Cyclic buffer in such mode can provide the visit of the mutual exclusion to buffer areaIt asks, thus does not need increase mutual exclusion protection between data receiver thread and data processing sub thread to carry out simultaneously, to haveStandby 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 ofSerial processing mode, does not accomplish concurrency substantially.The request long for processing holding time of this mode, efficiencyUnder 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, becauseOne 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 threadIt 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 dataIt is so able to solve the exclusive reference of data between thread, improves concurrency performance, but in fact, Circular buffer and circle queue formulaThe 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 asFruit 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 clothesWhen business device is received from the request of client, its IP address and port are recorded, then requests one son of creation for the clientThread 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 portsThe 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 openingAll ports, to prevent server by malicious attack.Thus will lead to data can not break through the limitation of firewall.AndEven if the not limitation of firewall, if client is specified to receive data from server Single port, client's termination will also result inReceive data failure.
(2) request sent for each client, server require one new port of distribution, since port providesSource is limited (at most only 65535), accordingly even when server performance is good again, processing routine is efficient again, in serverIn 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 skillLack 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 throughThe 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 serverDefault port on create global UDP socket;The request message that client is sent is monitored using global UDP socket;For prisonThe 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 UDPSocket option in word is positioned to allow for interim UDP socket and global UDP socket is tied to the mark of server simultaneouslyInformation, and the identification information of server and global UDP socket are bound;It is recycled and is monitored using global UDP socketRequest 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 clientIt include: interim UDP socket to be created in sub thread or process, and allow interim UDP socket to the identification information of serverIt is multiplexed;The first system function is called to bind the identification information of server and interim UDP socket;Call the second systemSystem function binds the identification information of client and interim UDP socket;It is sent by interim UDP socket to clientData 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 portThe 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 clientThe highest interim UDP socket of degree is as interim UDP socket;Interim UDP socket generate read signal, and from faceWhen 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 clientUDP socket is created on end, and the identification information of server is bound with UDP socket;By UDP socket to serviceDevice sends request message.
Further, after sending request message to server by UDP socket, further includes: calling system functionThe 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 mouldBlock, for creating global UDP socket on the default port of server;Module is monitored, for using global UDP socket prisonThe request message for listening client to send;Communication module for the interim UDP socket of request message creation to listen to, and is led toThe 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 socketOption is positioned to allow for interim UDP socket and global UDP socket is tied to the identification information of server simultaneously, and will clothesThe identification information of business device and global UDP socket are bound;Monitoring unit, for being monitored using global UDP socket circulationRequest 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 processWord is connect, and interim UDP socket is allowed to be multiplexed the identification information of server;First binding unit, for calling firstSystem function binds the identification information of server and interim UDP socket;Second binding unit, for calling the second systemSystem function binds the identification information of client and interim UDP socket;Communication unit, for being socketed by interim UDPWord 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 portUDP socket, and it is highest interim according to the identification information of server and/or the identification information of client selection matching degreeUDP socket is as interim UDP socket;Reading subunit, for interim UDP socket generate read signal, and fromInterim 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 mouldBlock is bound for creating UDP socket on the client, and by the identification information of server with UDP socket;Send mouldBlock, 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 functionThe 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 serverThe request message that family end is sent;Interim UDP socket is created for request message, and by the identification information and client of serverIdentification information and this UDP socket bind, and communicated by the interim socket of UDP with client, by using completeOffice's UDP socket listens to the request message of client transmission on default port, and asking of sending of respectively each clientIt asks message that an interim UDP socket is respectively created, has reached system kernel rank using the function that system kernel function providesConcurrent processing purpose, disappear to realize and only need to monitor the request that each client is sent on a default portBreath, without distributing a port for each interim socket, in addition, firewall only needs to open default portIt puts, while also breaching the technical effect in the quantity of the request message of same time access services device, and then solve correlationLack 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 andThe 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 hairBright 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 friendshipMutual schematic diagram;
Fig. 3 is the client's request according to the preferred embodiment of the invention received in server end concurrent processing from clientFlow 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 inventionAttached drawing, technical scheme in the embodiment of the invention is clearly and completely described, it is clear that described embodiment is onlyThe embodiment of a part of the invention, instead of all the embodiments.Based on the embodiments of the present invention, ordinary skill peopleThe model that the present invention protects all should belong in member's every other embodiment obtained without making creative workIt 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 wayData be interchangeable under appropriate circumstances, so as to the embodiment of the present invention described herein can in addition to illustrating herein orSequence other than those of description is implemented.In addition, term " includes " and " having " and their any deformation, it is intended that coverCover 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 toStep or unit those of is clearly listed, but may include be not clearly listed or for these process, methods, productOr 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 illustrateIt 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 hereinShown 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 packetInclude 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 visitorFamily 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 disappearBreath, without distributing a port for each interim socket, in addition, firewall only needs to open default portIt puts, while also breaching the technical effect in the quantity of the request message of same time access services device, and then solve correlationLack 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 andThe 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 meshIP 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 includeFollowing steps:
Step S1: by global UDP socket socket option (such as: SO_REUSEADDR) be positioned to allow for it is interimUDP socket and global UDP socket are tied to the identification information of server (including but not limited to: the IP of server simultaneouslyThe 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 messageWhen, 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 visitorIt 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 serverIdentification 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 clientWith 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 fromThe 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 visitorThe 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 visitorWhen family end is requested, client requests the creation reusable socket socket in one new address thus, and thus socket is responsible for itRemaining needs are communicated with the service logic that client carries out.Specifically, it can use system function function (i.e. above-mentioned the first systemFunction) bind (int bind (int sockfd, const struct sockaddr*myaddr, sock len_taddrlen);) be tied to the IP address of local server and port numbers on newly-built socket, then reutilization system functionFunction (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 socketIt 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 kernelDisperse the flow of request message in rank to each corresponding interim UDP socket.Meanwhile firewall only needs to open thisWell-known port, without distributing a port for each interim socket, in addition, be capable of the request message of concurrent processingMaximum 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), andThe network transmission layer address of one local is got up with sockets associated.For UDP, that is, by five yuan of scoket socketGroup P in P2 part (source IP address: source port) be appointed as local IP address and port, can be shown as in kernel byIt is bound on local IP and local port in the udp protocol control block (PCB) of this socket sockets associated.Process canWith by specific an IP address and Port BindingBundling to socket, but this IP address must belong to it where the network of host connectOne 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 thusConnection.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 sloganIt is 0, then kernel just selects a transient port when bind is called;If specified IP address is wildcard address, needleFor TCP, kernel will have connected until socket, alternatively, kernel issues datagram on socket for UDPWhen 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 connectionIt is: without three-way handshake.Only record external address is i.e. by the udp protocol control block (PCB) of this socket sockets associatedIn external IP and outside port on specified, use when to send datagram on this socket, that is, by thisThe part P3 (purpose IP address: destination port) in scoket socket five-tuple P is determined.It is then immediately returned to callProcess, thus just can ensure datagram only can be passed to the socket socket of IP specified by connect function and portOn 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 UDPSocket 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 socketHold 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 orRecvmsg 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 kernelThe datagram of protocol address specified by connect.Destination be this have connected UDP socket native protocol (such as: IPLocation 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 transmittedTo 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 withUDP 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 PIn 3 parts (P1 agreement, P2 source IP address: source port, P3 purpose IP address: destination port) determined, so justCan 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 withLower step:
Step S61: the interim UDP socket of whole to match with default port is obtained, and is believed according to the mark of serverBreath 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 socketRush 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 kernelOn port where client;And the data of server are sent to from client, and after received server-side to above-mentioned data, meetingThe associated reception buffer area of interim UDP socket descriptor is routed automatically to by kernel protocol stack, and in interim UDP socketIt 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'sTarget is placed into UDP datagram in the caching of suitable socket, is waken up on the socket because of the calling (example of input obstructionSuch as: select).UDP_INPUT passes through (source IP address: source port, purpose IP address: destination port) and UDP to datagramIn (local ip address: local port, outside ip address: outside port) of all socket sockets associateds matched.AndThe 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 mostThe socket of small wildcard coupling number.If there is multiple sockets " minimum " wildcard coupling number having the same, then specifically by whichSocket 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 ClientConnect function may also be called, is socket designated external IP address and outer end slogan.It is necessary which limits socketOnly 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 2It 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 callPseudocode, " * .lport " indicate that local IP is default and " * .* " indicates that external IP and outside port are default.In preferred embodimentUsed in monitoring socket be that (the third line in above table, that is, be limited on this interface for second of state in table 2The datagram of arrival), it thus can receive all users and request connection.And after receiving request connection, newly-built setWord is connect after bind system is called and connect system is called, the first state (the in above table will be converted intoTwo 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 principleSocket is as above-mentioned interim UDP socket.Minimum wildcard coupling number principle, which refers to UDP message message only, can be transmitted to mostOn 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 addressLocal portExternal addressOutside port
140.252.1.2923**
*23**
140.252.1.2923140.252.1.111500
In above table, three sockets on a host, " * " indicates default.When UDP receives a destination portFor 23 message segment when, call kernel function, search for entire Internet PCB table (referring herein to Internet PCB table beA transport layer list structure in kernel protocol stack, each single item in chained list are a protocol control block (PCB), protocol control blockIt 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 InternetIn PCB) find a matched PCB node.In order to determine wildcard coupling number, only consider in the preferred embodiment local and outerThe IP address in portion puts aside outer end slogan.Local port number is to have to matched, and otherwise datagram can not route at allOnto 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 inventionReach message segment.As shown in table 4,
Table 4
Local addressLocal portExternal addressOutside portWildcard coupling number
140.252.1.2923**1
*23**2
140.252.1.2923140.252.1.1115000
For example it is assumed that reaching message segment comes from 140.252.1.11, port 1500, destination is 140.252.1.29, endMouth 23, " * " indicate default.When compared with the second row in above table, external address wildcard is matched, and wildcard coupling number is1;When compared with the third line in above table, local address and the matching of external address wildcard, wildcard coupling number is 2;WhenWhen compared with the last line in above table, discovery local address, external address and outside port exact matching, wildcardCoupling number is 0.Using the matched principle of minimum wildcard, this message segment can be transmitted to socket interface corresponding to last lineOn, thus revealing client and being sent to the data of server can correctly be delivered on the socket socket associated by itTechnical 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 clientFlow 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 supervisingThe 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 allowingNewly-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 serverWhen, 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 setsockoptAddress be configured.
Step S316, the IP address of local server and port are tied to by server end respectively using system function bindOn 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 respectivelyIn 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) withTCP 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 UDPComplete duplicate binding: when an IP address and port have been tied in particular socket, same IP address and port may be used alsoTo be bundled on another socket.Moreover, if allowing duplicate binding completely, with also needing to bundle the same IPSO_REUSEADDR option is positioned to allow for completely duplicate binding by each socket of location and port could be complete.UpperIt 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 arrangedSO_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 canTo include following processing step:
Step S402, UDP socket is created on the client, and the identification information of server and UDP socket are carried outBinding;
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 S404Include following steps:
Step S7: calling system function receives from the reading of interim UDP socket from server corresponding with request messageResponse data.
In a preferred embodiment, Fig. 5 is according to the preferred embodiment of the invention from client transmission clientThe 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 connectIn 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 socketData 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 socketIt 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 holdRow 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 requestThe 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 prisonThe 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. 7Shown, monitoring module 20 may include: first processing units 200, for the socket option in global UDP socket to be arrangedTo allow interim UDP socket and global UDP socket to be tied to the identification information of server simultaneously, and by the mark of serverKnow information to be bound with global UDP socket;Monitoring unit 202 is asked for monitoring to wait using global UDP socket circulationMessage 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 intoInterim UDP socket is created in journey, and interim UDP socket is allowed to be multiplexed the identification information of server;First bindingUnit 302, for calling the first system function to bind the identification information of server and interim UDP socket;Second ties upOrder member 304, for calling second system function to bind the identification information of client and interim UDP socket;CommunicationUnit 306, for sending data to client by interim UDP socket and/or being read by interim UDP socket from clientTerminate the data received.
Optionally, communication unit 306 may include: coupling subelement (not shown), for obtaining and default portThe 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 clientThe highest interim UDP socket of degree is as above-mentioned interim UDP socket;Reading subunit (not shown), for facingWhen UDP socket generate read signal, and from receptions buffer area associated with interim UDP socket read from client terminationThe 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 requestThe sending device of message may include: processing module 40, for creating UDP socket on the client, and by the mark of serverKnow 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 functionResponse 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 embodimentThe 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 othersMode is realized.Wherein, the apparatus embodiments described above are merely exemplary, such as the division of the unit, Ke YiweiA kind of logical function partition, there may be another division manner in actual implementation, for example, multiple units or components can combine orPerson is desirably integrated into another system, or some features can be ignored or not executed.Another point, shown or discussed is mutualBetween coupling, direct-coupling or communication connection can be through some interfaces, the INDIRECT COUPLING or communication link of unit or moduleIt connects, can be electrical or other forms.
The unit as illustrated by the separation member may or may not be physically separated, aobvious as unitThe component shown may or may not be physical unit, it can and it is in one place, or may be distributed over multipleOn 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 unitIt is that each unit physically exists alone, can also be integrated in one unit with two or more units.Above-mentioned integrated listMember 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 productWhen, it can store in a computer readable storage medium.Based on this understanding, technical solution of the present invention is substantiallyThe 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 wordsIt embodies, which is stored in a storage medium, including some instructions are used so that a computerEquipment (can for personal computer, server or network equipment etc.) execute each embodiment the method for the present invention whole orPart steps.And storage medium above-mentioned includes: that USB flash disk, read-only memory (ROM, Read-Only Memory), arbitrary access are depositedReservoir (RAM, Random Access Memory), mobile hard disk, magnetic or disk etc. be various to can store program codeMedium.
The above is only a preferred embodiment of the present invention, it is noted that for the ordinary skill people of the artFor member, various improvements and modifications may be made without departing from the principle of the present invention, these improvements and modifications are also answeredIt is considered as protection scope of the present invention.

Claims (8)

CN201510931931.8A2015-12-152015-12-15Processing, sending method and the device of request messageActiveCN105553977B (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN201510931931.8ACN105553977B (en)2015-12-152015-12-15Processing, sending method and the device of request message

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN201510931931.8ACN105553977B (en)2015-12-152015-12-15Processing, sending method and the device of request message

Publications (2)

Publication NumberPublication Date
CN105553977A CN105553977A (en)2016-05-04
CN105553977Btrue CN105553977B (en)2019-05-24

Family

ID=55832913

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN201510931931.8AActiveCN105553977B (en)2015-12-152015-12-15Processing, sending method and the device of request message

Country Status (1)

CountryLink
CN (1)CN105553977B (en)

Families Citing this family (16)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN106131112A (en)*2016-06-142016-11-16上海电气集团股份有限公司A kind of rehabilitation training apparatus monitoring method and rehabilitation training of upper limbs equipment
CN106131180A (en)*2016-07-082016-11-16深圳市沃特沃德股份有限公司The processing method of the many concurrent requests of intelligent terminal, Apparatus and system
CN106790022B (en)*2016-12-142019-06-18福建天泉教育科技有限公司Communication means and its system based on more inquiry threads
CN107132799A (en)*2017-06-212017-09-05湖南利能科技股份有限公司A kind of apparatus and method of many MCU data interactions intelligent acquisitions
CN109474661B (en)*2018-09-252021-05-14视联动力信息技术股份有限公司Method and system for processing network request event
CN111511041B (en)*2019-01-312022-03-29大唐移动通信设备有限公司Remote connection method and device
CN110011967A (en)*2019-02-272019-07-12新奥特(北京)视频技术有限公司A kind of method and system for data transmission
CN110166479B (en)*2019-05-312022-02-01深圳市瑞云科技有限公司Method for improving UDP (user Datagram protocol) sending efficiency of transmission system
CN113726723B (en)*2020-05-262023-11-03杭州萤石软件有限公司UDP-based data transmission method, device and equipment
CN112492054A (en)*2020-11-052021-03-12杭州萤石软件有限公司Multiplexing method, device and equipment for UDP (user Datagram protocol) port
CN112579210B (en)*2020-12-302024-10-25上海众源网络有限公司Application program control method and device
CN113162932B (en)*2021-04-232023-01-06航天新通科技有限公司Asynchronous I/O operation method and device based on socket
CN114244758B (en)*2021-12-132024-06-25武汉斗鱼鱼乐网络科技有限公司Network diagnosis method, storage medium, electronic equipment and system of android platform
CN114938395B (en)*2022-05-112024-08-02北京字节跳动网络技术有限公司Service response method, device, equipment and storage medium
CN115174214A (en)*2022-07-052022-10-11中孚安全技术有限公司Method and system for packet capturing of operating system application layer global network
CN115580581B (en)*2022-09-282025-05-16紫光计算机科技有限公司 Inter-process communication method, device, electronic device and storage medium

Citations (2)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN102624651A (en)*2012-03-082012-08-01北京神州数码思特奇信息技术股份有限公司Gateway communication method and device
CN103763156A (en)*2014-01-282014-04-30中国移动(深圳)有限公司Network speed measurement method and system

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN103117895B (en)*2013-01-252016-01-13哈尔滨工业大学A kind of services listen method of LXI instrument
CN104410982B (en)*2014-11-192017-11-14南京邮电大学Terminal polymerization and reconstructing method in a kind of Wireless Heterogeneous Networks

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN102624651A (en)*2012-03-082012-08-01北京神州数码思特奇信息技术股份有限公司Gateway communication method and device
CN103763156A (en)*2014-01-282014-04-30中国移动(深圳)有限公司Network speed measurement method and system

Also Published As

Publication numberPublication date
CN105553977A (en)2016-05-04

Similar Documents

PublicationPublication DateTitle
CN105553977B (en)Processing, sending method and the device of request message
CN108377671B (en) Method and computer device for processing message
Wetherall et al.Introducing new internet services: Why and how
US20040177158A1 (en)Network address translation techniques for selective network traffic diversion
CN106209648B (en)Multicast data packet forwarding method and apparatus across virtual expansible local area network
MXPA04002729A (en)Transmitting and receiving messages through a customizable communication channel and programming model.
CN102027732B (en) Provides access to server applications via an Internet Protocol network
CN106031133A (en)An anycast based, wide area distributed mapping and load balancing system
CN101364976B (en)Method and apparatus for establishing communication channel and data communication system
AU2001296185A1 (en)Configuration of a flexible infrastructure
CN103238301A (en)Technique for managing traffic at router
EP1334582A1 (en)Configuration of a flexible infrastructure
CN109525684A (en)Message forwarding method and device
CN107864101A (en)Load-balancing method and device
CN109194525A (en)A kind of network node configuration method and management node
US8782147B2 (en)Concurrent delivery for messages from a same sender
CN107508836B (en)A kind of method and device that acl rule issues
CN103827830B (en)System and method for preventing "bottleneck" in transactional middleware machine environment
CN105554176B (en)Send the method, apparatus and communication system of message
US7660906B1 (en)Data delivery system and method
JP4896532B2 (en) Communication channel model
CN109413224A (en)Message forwarding method and device
CN109474713A (en)Message forwarding method and device
CN102761608A (en)UDP (User Datagram Protocol) conversation multiplexing method and load balancing equipment
CN104219257B (en)A kind of webpage real-time communication method, system and server and client side

Legal Events

DateCodeTitleDescription
C06Publication
PB01Publication
C10Entry into substantive examination
SE01Entry into force of request for substantive examination
GR01Patent grant
GR01Patent grant

[8]ページ先頭

©2009-2025 Movatter.jp