CN111314273B - Data transmission method and connection device based on UDP (user Datagram protocol) - Google Patents

Data transmission method and connection device based on UDP (user Datagram protocol) Download PDF

Info

Publication number
CN111314273B
CN111314273B CN201811520003.2A CN201811520003A CN111314273B CN 111314273 B CN111314273 B CN 111314273B CN 201811520003 A CN201811520003 A CN 201811520003A CN 111314273 B CN111314273 B CN 111314273B
Authority
CN
China
Prior art keywords
address
socket
port
connection
data packet
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
CN201811520003.2A
Other languages
Chinese (zh)
Other versions
CN111314273A (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.)
Alibaba Group Holding Ltd
Original Assignee
Alibaba Group Holding 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 Alibaba Group Holding Ltd filed Critical Alibaba Group Holding Ltd
Priority to CN201811520003.2A priority Critical patent/CN111314273B/en
Publication of CN111314273A publication Critical patent/CN111314273A/en
Application granted granted Critical
Publication of CN111314273B publication Critical patent/CN111314273B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/16Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
    • H04L69/161Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields
    • H04L69/162Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields involving adaptations of sockets based mechanisms
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D30/00Reducing energy consumption in communication networks
    • Y02D30/50Reducing energy consumption in communication networks in wire-line communication networks, e.g. low power modes or reduced link rate

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer And Data Communications (AREA)

Abstract

The application discloses a data transmission method and a connection device based on UDP. The UDP-based data transmission method comprises the following steps: binding the server address and the port as a monitoring address to the monitoring socket; when the monitoring socket receives a first data packet, a connection socket is established; binding the server address and the port as a local connection address to the connection socket; binding a client address and a port as opposite end connection addresses to the connection socket, wherein the client address and the port are obtained from the first data packet; and receiving and transmitting data by using the connection socket. The data transmission method and device based on UDP can allow the original process to be closed to quit after the connection socket processes the data, thereby ensuring that the service is not interrupted.

Description

Data transmission method and connection device based on UDP (user Datagram protocol)
Technical Field
The present application relates to the field of computer information processing, and in particular, to a UDP-based data transmission method and a connection device.
Background
UDP (user datagram protocol) is a communication protocol, and compared with TCP protocol which is connection-oriented, UDP is a connectionless-oriented communication protocol, and the basic communication model is shown in fig. 1. The left side of fig. 1 is the operation flow of the server, and the right side is the operation flow of the client. As shown in fig. 1, a server first creates a socket (socket), then binds an address of the server, and transmits and receives data after binding; the client firstly creates a socket, and data transmission can be carried out between the client and the server according to the address of the server after the socket is created. When the processes of the server and the client are finished, the server and the client end are connected.
In the step of binding the address, the UDP server usually calls a bind () function to bind the local address/port to the socket created by the server, and sends a message through a sendto () function after the binding is finished. At the client, before the client sends information to the server, the socket of the client is randomly assigned a local address/port by the operating system. When the client sends the message according to the local address/port bound by the bind () function of the server, the client can carry the local address/port, so that the server can know the local address/port of the client, and the point-to-point message transmission of the client and the server is realized.
The use of reliable transport protocols, such as the quic protocol, implemented based on UDP is becoming more common. In the traditional UDP application, a reuse port is adopted in multiple processes to realize load balancing. Each process is monitored on the same UDP port by a monitoring socket (socket), all data packets are transmitted and received by the monitoring socket, and the reuse port ensures that the data sent by the same client address are distributed to the same process. However, when the process is restarted, the new and original processes are alternated, the monitoring port needs to be closed in the original process, and the monitoring port needs to be started in the new process, which may cause the original connection interruption of the original process based on UDP, resulting in data transmission error and poor client experience.
Disclosure of Invention
In view of the foregoing problems, an embodiment of the present invention provides a UDP-based data transmission method and a connection device, so as to solve the problems in the prior art.
In order to solve the above problem, an embodiment of the present application discloses a data transmission method based on UDP, including:
binding the server address and the port as a monitoring address to the monitoring socket;
when the monitoring socket receives a first data packet, a connection socket is established;
binding the server address and the port as a local connection address to the connection socket; binding a client address and a port as opposite end connection addresses to the connection socket, wherein the client address and the port are obtained from the first data packet;
and receiving and transmitting data by using the connection socket.
In order to solve the above problem, an embodiment of the present application discloses a data transmission apparatus based on UDP, including:
the first binding module is used for binding the server address and the port as a monitoring address to the monitoring socket;
a connection socket creating module, configured to create a connection socket when the monitoring socket receives the first data packet;
the second binding module is used for binding the server address and the port serving as a local connection address to the connection socket;
A third binding module, configured to bind a client address and a port, which are obtained from the first data packet, as an opposite-end connection address to the connection socket;
and the transceiving module is used for transceiving the data packet by utilizing the connection socket.
An embodiment of the present application further discloses a terminal device, including:
one or more processors; and
one or more machine readable media having instructions stored thereon that, when executed by the one or more processors, cause the terminal device to perform the above-described methods.
One or more machine-readable media having instructions stored thereon, which when executed by one or more processors, cause the processors to perform the above-described methods are also disclosed.
As can be seen from the above, the embodiments of the present application include the following advantages:
according to the data transmission method and device based on the UDP, the newly-built connecting sleeve interface is separated from the original monitoring sleeve interface in the framework through newly-built connecting sleeve interfaces and binding the local connection address and port and the opposite connection address and port, and the newly-built connecting sleeve interfaces are used for receiving and sending data. When the process is restarted, the operation of closing the monitoring socket of the original process to be closed and creating a new monitoring socket of the new process to be opened does not affect the communication of the established connecting sleeve interface, so that the original process to be closed can quit after the data is processed by the connecting socket, and the service is ensured not to be interrupted.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and those skilled in the art can also obtain other drawings according to the drawings without creative efforts.
Fig. 1 is a diagram of a basic model of UDP connection in the prior art.
Fig. 2 is a schematic diagram of the core concept of the present application.
Fig. 3 is a flowchart of a UDP-based data transmission method according to a first embodiment of the present application.
Fig. 4 is a flowchart of a UDP-based data transmission method according to a second embodiment of the present application.
Fig. 5 is a block diagram of a UDP-based data transmission apparatus according to a third embodiment of the present application.
Fig. 6 is a block diagram of a UDP-based data transmission apparatus according to a third embodiment of the present application.
Fig. 7 schematically shows a block diagram of a terminal device for performing the method according to the invention.
Fig. 8 schematically shows a memory unit for holding or carrying program code implementing the method according to the invention.
Detailed Description
The technical solutions in the embodiments of the present application will be described clearly and completely with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only some embodiments of the present application, and not all embodiments. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments in the present application are within the scope of protection of the present application.
One of the core ideas of the present application is to provide a UDP-based data transmission method and apparatus, as shown in fig. 2, in an embodiment, a socket () function of a UDP protocol is used to create a new monitoring socket, a bind () function is used to bind a local address and a port of a server, and a recvmesg () function is used to receive a data packet, and then a socket () function is used to create a new connection sleeve interface. Binding a server address and a port by using a bind () function, and binding an opposite end address and a port for data transmission by using a connect () function, thereby realizing the binding of socket quadruplets, so that a newly-built connection socket can receive and transmit data of the opposite end address and the port, the work of a connection sleeve interface is not influenced when a process is closed, after a new process is built, the connection of the original process is continuous, and the problems of the connectivity of multi-process UDP application and the interruption of old connection of multi-process restarting in the prior art are solved.
First embodiment
A first embodiment of the present invention provides a UDP-based data transmission method. The method provided by the embodiment of the invention can be applied between the server and the client which need to perform data transmission. Fig. 3 is a flowchart illustrating steps of a UDP-based data transmission method according to a first embodiment of the present invention. As shown in fig. 3, the UDP-based data transmission method according to the embodiment of the present invention includes the following steps:
s101, binding a server address and a port as a monitoring address to a monitoring socket;
before data transmission, a server that needs to perform data transmission may create a monitoring socket of UDP, where the monitoring socket is used to obtain each data packet sent to a port of the server address. The listening socket has a listening address, such as an IP address and port number, which needs to be listened to. In this step, the server address and the port number may be used as the snooping address, so as to snoop the server. The operation of creating a listening socket for a server may be implemented by a socket () function of UDP, for example. After the listening socket is created, the local listening address and port of the server may be bound with the bind () function of UDP to receive data through the recvmsg () function.
After step S101 is performed, step S102 may be performed as follows:
s102, when the monitoring socket receives a first data packet, a connection socket is established;
in this step, when the listening socket receives the first packet, a new socket for the connection, referred to herein as the connection socket, is created. The connection socket is established, for example, by the socket () function of UDP. The connection socket is used for connecting two ends of communication, namely a local end and an opposite end. And realizing communication between the two ends by using the local connection address of the local end and the opposite end connection address of the opposite end.
After step S102 is performed, step S103 may be performed as follows:
s103, binding the server address and the port as local connection addresses to the connection socket;
in this step, the server address and the port can be used as the local connection address of the local side, and the local connection address and the port can be bound for the connection socket by using the bind () function. After such operation, the server address and the port are used as the monitoring address of the monitoring socket and the local connection address of the connection socket, and the monitoring socket and the connection sleeve interface are bound with the same local connection address and port.
In some cases, according to the UDP protocol, the bind () function requires that by default, a socket cannot be bound to an already in use local address and port, SO in embodiments of the present invention, the setsockopt () function may be modified, SO _ REUSEADDR bootl allowing the socket to be bound to an already in use address and port, SO that the adapter socket interface may be bound to the already in use local address and port of the server.
After step S103 is performed, step S104 may be performed as follows:
s104, binding the client address and the port as the opposite end connection address to the connection socket, and obtaining the client address and the port from the first data packet
In this step, the connection () function of UDP can be reused to bind the opposite end of data transmission, such as the address and port of the client, so as to complete the binding of UDP quadruple, the server and the client can transmit data packets point to point, and the connectivity based on the reliable transport protocol over UDP is maintained by the communication of the connection sleeve interface.
The difference between the step and the prior art is that, in the prior art, the UDP service directly receives and sends data through the monitoring socket by using the sendto () function, in the embodiment of the present invention, a new connection socket is created, the local connection address and port which are the same as the monitoring socket are bound by using the blind () function of the UDP, the opposite connection address and port are bound by the connect () function, and the local connection address and port of the server and the opposite connection address and port are respectively bound by using the bind () function and the connect () function, so as to complete the binding of the quadruplet.
The method provided by the embodiment of the invention creatively creates the connecting sleeve interface, applies the connect () function to bind the quadruple, and the connecting sleeve interface only receives and transmits the data packet of the specific address after binding. The original monitoring socket only processes data packets of unbound client addresses, and the data packets are data packets of unknown addresses which are not connected to the server. The significance of the newly created connection socket and connect () function is that a socket is additionally created to handle communications for a particular client address and port.
After performing step S104, step S105 may be performed as follows:
s105, transmitting and receiving data packets by using the connection socket;
in this step, for the created connection sleeve interface, the data packet can be transmitted and received through other functions such as recv/send ().
Since the connect () function already binds the opposite terminal connection address and the port, the recv/send () function of UDP does not need to carry the opposite terminal connection address, and compared with the recvmsg () function used for sending and receiving information in the prior art, recv/send () is a calling function with the same function but lighter weight, so that the consumption of the system can be lower.
As can be seen from the above, in the data transmission method based on UDP provided in the embodiment of the present invention, the newly-built connection socket is configured to separate from the original monitoring socket by creating a connection socket and binding the local connection address and port and the opposite connection address and port, and the newly-built connection socket is used for receiving and transmitting data. When the process is restarted, the operation of closing the monitoring socket of the original process to be closed and creating a new monitoring socket of the new process to be opened does not affect the communication of the established connecting sleeve interface, so that the original process to be closed can quit after the data is processed by the connecting socket, and the service is ensured not to be interrupted.
In contrast, the prior art method of utilizing a reuse port does not solve the problem of connection interruption during the process restart. To ensure that the connection is not interrupted during the restart process, additional inter-process communication overhead needs to be added, which causes a large performance loss, and the programming architecture for UDP is complicated. The proposal provided by the embodiment of the invention solves the difficulty of the reliable transmission protocol based on UDP in the multi-process programming and simplifies the flow of UDP programming.
Second embodiment
A second embodiment of the present invention provides a UDP-based data transmission method. Fig. 4 is a flowchart illustrating steps of a UDP-based data transmission method according to a second embodiment of the present invention. As shown in fig. 4, the UDP-based data transmission method according to the embodiment of the present invention includes the following steps:
s201, binding a server address and a port as a monitoring address to a monitoring socket;
s202, when the monitoring socket receives the first data packet, a connection socket is established;
s203, binding the server address and the port as a local connection address to the connection socket;
s205, binding a client address and a port as an opposite end connection address to the connection socket, wherein the client address and the port are obtained from the first data packet;
and S208, utilizing the connection socket to receive and transmit data.
The steps S201 to S203, S205 and S208 are the same as or similar to the steps S101 to S105 in the previous embodiment, and are not repeated herein. The present embodiment focuses on the differences from the previous embodiment.
In an alternative embodiment, before the step of binding the server address and the port as the snooping address to the snooping socket in step S201, the method further includes the following steps:
S200, a monitoring socket is created for the server.
In this step, before data transmission, the server that needs to perform data transmission may create a listening socket of UDP, where the listening socket is used to obtain each data packet sent to the port of the server address. The listening socket has a listening address, such as an IP address and a port number, to be listened to.
In an alternative embodiment, before step S205, that is, binding the client address and the port as the peer connection address to the connection socket, the method may further include the following steps:
s204, obtaining the client address and the port from the first data packet.
Upon receiving the first packet, the client address and port may be obtained from the first packet. The first data packet is a data packet sent by a specific client, and carries the address and the port of the client. The address and port of the client may be obtained in this step for subsequent binding operations.
In an alternative embodiment, after step S205, that is, after the step of binding the client address and the port as the peer connection address to the connection socket, the present invention may further include the following steps:
S206, when the connection socket receives a second data packet, judging whether the source address of the second data packet is matched with the address and the port of the client;
s207, when the source address of the second data packet is not matched with the address and the port of the client, the second data packet is sent to the monitoring socket.
In one embodiment, the operation of binding the local address and the port with the bind () function and the atomic operation of binding the peer address and the port with the connect () function may be implemented with a setsockopt () native function of the UDP protocol. An atomic operation is to combine two steps into one so that no other operation can be inserted between the two.
In actual operation, setsockopt () function can be extended by a kernel, and functions are added to realize atomic operation of binding by using a bind () function and binding by using a connect () function, so that a created connection socket is prevented from receiving other data packets before the created connection socket is bound by using the connect () function after the bind () function is used for binding operation.
After setsockopt () is expanded, two original actions, namely binding by using a bind () function and binding by using a connect () function, are ensured to be one, and a data packet of other addresses cannot be received in the middle; when a second packet is received between the two operations, it may be determined in step S206 whether the packet is a packet sent by the client address and port. If the determination result is negative, that is, the source address of the second packet is not the bound client address and port, the second packet may be sent to the monitoring socket in step S207, and the monitoring socket processes the received new packet, so as to ensure that no new packet is inserted between the two operations of binding the local link address and port and binding the peer connection address and port.
In an alternative embodiment, the present invention may further comprise the steps of:
s209, searching the data packets received by the monitoring socket and the connection socket by using a hash searching mode;
in this step, the core may be modified with UDP packet receiving logic, and a packet receiving lookup manner of a socket of UDP bound to the same address is modified from linked list lookup to hash lookup, that is, after the core receives a data packet sent by the network card, the data packet needs to be distributed to a buffer of a corresponding socket.
In an embodiment, related functions such as the kernel __ UDP4_ lib _ lookup of the UDP protocol may be modified, and a linked list lookup manner of multiple socket lookup manners under the same snooping port during packet receiving is changed from a linked list lookup to a hash lookup. The packet receiving searching mode is changed from linked list searching to hash searching, and the problem that CPU soft interrupt occupies high under high concurrency can be solved.
In an alternative embodiment, the method may further comprise the steps of:
s210, after the data transmission is detected to be finished, closing the connecting sleeve interface;
in one embodiment, when a reliable transport over UDP connection ends, the connection socket may be closed via the close () function of UDP.
In this step, the newly created connection sleeve interface can be closed by a close function, and since the connection socket is separated from the monitoring socket in the framework, when the process is restarted, the original process closes the first socket for monitoring and the new process creates another new monitoring socket, so that the communication of the connection sleeve interface is not influenced. The connecting sleeve interface can be closed and withdrawn after the connecting sleeve interface combs data, and service is guaranteed to be uninterrupted.
As can be seen from the above, in the UDP-based data transmission method according to the second embodiment of the present invention, a new connection socket is created and the local connection address and port and the opposite connection address and port are bound, so that the new connection socket is separated from the original monitoring socket in the architecture, and the new connection socket is used for receiving and sending data. When the process is restarted, the operations of closing the monitoring socket by the original process to be closed and creating a new monitoring socket by the new process to be opened do not affect the communication of the established connecting sleeve interface, so that the original process to be closed can quit after the data is processed by the connecting socket, and the service is ensured not to be interrupted.
In contrast, the prior art method of utilizing reuse port does not solve the problem of connection interruption during the process restart. To ensure that the connection is not interrupted during the restart process, additional inter-process communication overhead needs to be added, which causes a large performance loss, and the programming architecture for UDP is complicated. The proposal provided by the embodiment of the invention solves the difficulty of the reliable transmission protocol based on UDP in the multi-process programming and simplifies the flow of UDP programming.
In an optional embodiment, for example, in a multi-process service, the method and the apparatus provided in the embodiments of the present invention adopt a UDP connect mode and a scheme of kernel modification, thereby solving a UDP connectivity problem and a connection interruption problem in a process restart process caused by a conventional UDP programming.
In an optional embodiment, the scheme provided by the embodiment of the present invention may extend a setsockopt function by a kernel, and add a function to implement the atomic operation of the step of binding the local address and the port and binding the opposite address and the port, thereby preventing the created connection sleeve interface from receiving other data packets before the connect operation after the bind operation.
In an optional embodiment, the scheme provided by the embodiment of the invention can modify UDP packet receiving logic for the kernel, change the packet receiving searching mode of the socket based on the UDP protocol bound at the same address from linked list searching to hash searching, and solve the problem of high CPU soft interrupt occupation under high concurrency.
Third embodiment
A third embodiment of the present invention provides a UDP-based data transmission apparatus, as shown in fig. 5, including:
a first binding module 301, configured to bind a server address and a port as a monitoring address to a monitoring socket;
a connection sleeve interface creating module 302, configured to create a connection sleeve interface when the monitoring sleeve interface receives the first data packet;
A second binding module 303, configured to bind the server address and the port as a local connection address to the connection socket;
a third binding module 304, configured to bind, as an opposite connection address, a client address and a port to the connection socket, where the client address and the port are obtained from the first data packet;
a transceiving module 305, configured to transceive a data packet using the connection socket.
In summary, the UDP-based data transmission apparatus provided in this embodiment has at least the following advantages:
in the UDP-based data transmission apparatus according to the third embodiment of the present invention, a new connection socket is created and an address and a port of an opposite end are bound, a new connection socket interface is separated from a monitoring socket in a framework, and a new connection socket function is used for receiving and transmitting data. When the process is restarted, the operation of closing the monitoring socket by the original process to be closed and establishing a new monitoring socket by the new process to be opened does not influence the communication of the established connecting sleeve interface, which means that the original process to be closed can quit after the data is processed by the connecting socket, thereby ensuring that the service is not interrupted.
In contrast, the prior art method of utilizing a reuse port does not solve the problem of connection interruption during the process restart. To ensure that the connection is not interrupted during the restart process, additional inter-process communication overhead needs to be added, which causes a large performance loss, and the programming architecture for UDP is complicated. The proposal provided by the embodiment of the invention solves the difficulty of the reliable transmission protocol based on UDP in the multi-process programming and simplifies the flow of UDP programming.
Fourth embodiment
A fourth embodiment of the present invention provides a UDP-based data transmission apparatus, as shown in fig. 6, including:
a first binding module 401, configured to bind a server address and a port as a monitoring address to a monitoring socket;
a connection sleeve interface creating module 402, configured to create a connection sleeve interface when the monitoring sleeve interface receives the first data packet;
a second binding module 403, configured to bind the server address and the port as a local connection address to the connection socket;
a third binding module 405, configured to bind a client address and a port, which are obtained from the first data packet, as an opposite-end connection address to the connection socket;
the transceiving module 408 is configured to transceive a data packet using the connection socket.
In an alternative embodiment, the apparatus further comprises:
an obtaining module 404, configured to obtain a client address and a port from the first data packet.
In an optional embodiment, the apparatus further comprises:
a monitoring socket creating module 400, configured to create a monitoring socket for the server.
In an optional embodiment, the apparatus further comprises:
A closing module 410, configured to close the connection sleeve interface after detecting that data transceiving is finished
In an optional embodiment, the apparatus further comprises:
a determining module 406, configured to determine, when the connection socket receives a second data packet, whether a source address of the second data packet matches the client address and the port;
a sending module 407, configured to send the second data packet to the monitoring socket when the source address of the second data packet is not matched with the address and the port of the client.
In an optional embodiment, the apparatus further comprises:
and the searching module 409 is configured to search the monitoring socket and the data packet received by the connection socket in a hash searching manner.
In an optional embodiment, the binding operation is implemented by a connect function of a UDP protocol.
In summary, the UDP-based data transmission apparatus provided in this embodiment has at least the following advantages:
as can be seen from the above, in the UDP-based data transmission apparatus according to the fourth embodiment of the present invention, the newly-built connection socket and the binding of the local connection address and port and the opposite connection address and port are used to separate the newly-built connection socket from the original monitoring socket in the architecture, and the newly-built connection socket is used for receiving and transmitting data. When the process is restarted, the operation of closing the monitoring socket of the original process to be closed and creating a new monitoring socket of the new process to be opened does not affect the communication of the established connecting sleeve interface, so that the original process to be closed can quit after the data is processed by the connecting socket, and the service is ensured not to be interrupted.
In contrast, the prior art method of utilizing a reuse port does not solve the problem of connection interruption during the process restart. To ensure that the connection is not interrupted during the restart process, additional inter-process communication overhead needs to be added, which causes a large performance loss, and the programming architecture for UDP is complicated. The proposal provided by the embodiment of the invention solves the difficulty of the reliable transmission protocol based on UDP in the multi-process programming and simplifies the flow of UDP programming.
Besides, the UDP-based data transmission apparatus provided in this embodiment further includes at least the following advantages:
in the multi-process service, the method and the device provided by the embodiment of the invention adopt a UDP connect mode and a kernel reconstruction scheme, and solve the problems of UDP connectivity and connection interruption in the process restarting process caused by the traditional UDP programming.
In an optional embodiment, the scheme provided by the embodiment of the present invention may extend a setsockopt function by a kernel, and add a function to implement the atomic operation of the step of binding the local address and the port and binding the opposite address and the port, thereby preventing the created connection sleeve interface from receiving other data packets before the connect operation after the bind operation.
In an optional embodiment, the scheme provided by the embodiment of the invention can modify UDP packet receiving logic for the kernel, change the packet receiving searching mode of the socket based on the UDP protocol bound at the same address from linked list searching to hash searching, and solve the problem of high CPU soft interrupt occupation under high concurrency.
For the apparatus embodiment, since it is substantially similar to the method embodiment, the description is relatively simple, and reference may be made to the partial description of the method embodiment for relevant points.
Fig. 7 is a schematic hardware structure diagram of a terminal device according to an embodiment of the present application. As shown in fig. 7, the terminal device may include an input device 90, a processor 91, an output device 92, a memory 93, and at least one communication bus 94. The communication bus 94 is used to enable communication connections between the elements. The memory 93 may comprise a high speed RAM memory, and may also include a non-volatile storage NVM, such as at least one disk memory, in which various programs may be stored in the memory 93 for performing various processing functions and implementing the method steps of the present embodiment.
Alternatively, the processor 91 may be implemented by, for example, a Central Processing Unit (CPU), an Application Specific Integrated Circuit (ASIC), a Digital Signal Processor (DSP), a Digital Signal Processing Device (DSPD), a Programmable Logic Device (PLD), a Field Programmable Gate Array (FPGA), a controller, a microcontroller, a microprocessor, or other electronic components, and the processor 91 is coupled to the input device 90 and the output device 92 through a wired or wireless connection.
Alternatively, the input device 90 may include a variety of input devices, such as at least one of a user-oriented user interface, a device-oriented device interface, a software-programmable interface, a camera, and a sensor. Optionally, the device interface facing the device may be a wired interface for data transmission between devices, or may be a hardware plug-in interface (e.g., a USB interface, a serial port, etc.) for data transmission between devices; optionally, the user-facing user interface may be, for example, a user-facing control key, a voice input device for receiving voice input, and a touch sensing device (e.g., a touch screen with a touch sensing function, a touch pad, etc.) for receiving user touch input; optionally, the programmable interface of the software may be, for example, an entry for a user to edit or modify a program, such as an input pin interface or an input interface of a chip; an audio input device such as a microphone may receive voice data. The output device 92 may include a display, a sound, or other output device.
In this embodiment, the processor of the terminal device includes a module for executing the functions of the modules of the data processing apparatus in each device, and specific functions and technical effects may refer to the foregoing embodiments, which are not described herein again.
Fig. 8 is a schematic hardware structure diagram of a terminal device according to another embodiment of the present application. FIG. 8 is a specific embodiment of FIG. 7 in an implementation. As shown in fig. 8, the terminal device of the present embodiment includes a processor 101 and a memory 102.
The processor 101 executes the computer program code stored in the memory 102 to implement the UDP-based data transmission method of fig. 2 to 3 in the above-described embodiment.
The memory 102 is configured to store various types of data to support operations at the terminal device. Examples of such data include instructions for any application or method operating on the terminal device, such as messages, pictures, videos, and so forth. The memory 102 may include a Random Access Memory (RAM) and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.
Optionally, the processor 101 is provided in the processing assembly 100. The terminal device may further include: a communication component 103, a power component 104, a multimedia component 105, an audio component 106, an input/output interface 107 and/or a sensor component 108. The specific components included in the terminal device are set according to actual requirements, which is not limited in this embodiment.
The processing component 100 generally controls the overall operation of the terminal device. The processing component 100 may include one or more processors 101 to execute instructions to perform all or part of the steps of the methods of fig. 2-3 described above. Further, the processing component 100 can include one or more modules that facilitate interaction between the processing component 100 and other components. For example, the processing component 100 may include a multimedia module to facilitate interaction between the multimedia component 105 and the processing component 100.
The power supply component 104 provides power to the various components of the terminal device. The power components 104 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the terminal device.
The multimedia component 105 includes a display screen that provides an output interface between the terminal device and the user. In some embodiments, the display screen may include a Liquid Crystal Display (LCD) and a Touch Panel (TP). If the display screen includes a touch panel, the display screen may be implemented as a touch screen to receive an input signal from a user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundary of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation.
The audio component 106 is configured to output and/or input audio signals. For example, the audio component 106 may include a Microphone (MIC) configured to receive external audio signals when the terminal device is in an operational mode, such as a voice recognition mode. The received audio signal may further be stored in the memory 102 or transmitted via the communication component 103. In some embodiments, the audio component 106 also includes a speaker for outputting audio signals.
The input/output interface 107 provides an interface between the processing component 100 and peripheral interface modules, which may be click wheels, buttons, etc. These buttons may include, but are not limited to: a volume button, a start button, and a lock button.
The sensor component 108 includes one or more sensors for providing various aspects of status assessment for the terminal device. For example, the sensor component 108 can detect the open/closed status of the terminal device, the relative positioning of the components, the presence or absence of user contact with the terminal device. The sensor assembly 108 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact, including detecting the distance between the user and the terminal device. In some embodiments, the sensor assembly 108 may also include a camera or the like.
The communication component 103 is configured to facilitate communication between the terminal device and other devices in a wired or wireless manner. The terminal device may access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In one embodiment, the terminal device may include a SIM card slot for inserting a SIM card therein, so that the terminal device can log on to a GPRS network and establish communication with the server via the internet.
From the above, the communication component 103, the audio component 106, the input/output interface 107 and the sensor component 108 involved in the embodiment of fig. 8 can be implemented as the input device in the embodiment of fig. 7.
An embodiment of the present application provides a terminal device, including: one or more processors; and one or more machine readable media having instructions stored thereon that, when executed by the one or more processors, cause the terminal device to perform a method as described in one or more of the embodiments of the application.
The embodiments in the present specification are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other.
While preferred embodiments of the present application have been described, additional variations and modifications of these embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including the preferred embodiment and all changes and modifications that fall within the true scope of the embodiments of the present application.
Finally, it should also be noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or terminal that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or terminal. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or terminal that comprises the element.
The UDP-based data transmission method and connection device provided by the present application are introduced in detail above, and specific examples are applied in the text to explain the principles and embodiments of the present application, and the descriptions of the above embodiments are only used to help understand the method and the core ideas of the present application; meanwhile, for a person skilled in the art, according to the idea of the present application, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present application.

Claims (14)

1. A UDP-based data transmission method includes:
binding the server address and the port as a monitoring address to the monitoring socket;
when the monitoring socket receives a first data packet, a connection socket is established;
binding the server address and the port as a local connection address to the connection socket;
binding a client address and a port as opposite end connection addresses to the connection socket, wherein the client address and the port are obtained from the first data packet; and
receiving and transmitting data by using the connection socket;
the connection socket is used for receiving and transmitting the first data packet;
The monitoring socket is used for processing a second data packet, and the client address and the port corresponding to the second data packet are not bound.
2. The method of claim 1, wherein prior to the step of binding the server address and the port as a snooping address to a snooping socket, the method further comprises:
and creating a monitoring socket aiming at the server.
3. The method of claim 1, further comprising:
and closing the connection socket after detecting that the data receiving and sending are finished.
4. The method of claim 1, after the step of creating a connection socket, the method further comprising:
when the connection socket receives a second data packet, judging whether the source address of the second data packet is matched with the client address and the port;
and when the source address of the second data packet is not matched with the address and the port of the client, sending the second data packet to the monitoring socket.
5. The method of claim 1, further comprising:
and searching the data packets received by the monitoring socket and the connecting socket in a hash searching mode.
6. The method according to claim 1, wherein in the step of binding the server address and the port as a local connection address to the connection socket and in the step of binding the client address and the port as a peer connection address to the connection socket, the binding operation is implemented by a connect function of UDP protocol.
7. A UDP-based data transmission apparatus, comprising:
the first binding module is used for binding the server address and the port as a monitoring address to the monitoring socket;
a connection socket creating module, configured to create a connection socket when the monitoring socket receives the first data packet;
the second binding module is used for binding the server address and the port serving as a local connection address to the connection socket;
a third binding module, configured to bind a client address and a port, which are obtained from the first data packet, as an opposite-end connection address to the connection socket; and
the receiving and transmitting module is used for receiving and transmitting data packets by using the connecting sleeve interface;
the connection socket is used for receiving and transmitting the first data packet;
The monitoring socket is used for processing a second data packet, and the client address and the port corresponding to the second data packet are not bound.
8. The apparatus of claim 7, further comprising:
and the monitoring socket creating module is used for creating a monitoring socket aiming at the server.
9. The apparatus of claim 7, further comprising:
and the closing module is used for closing the connection socket after the end of data receiving and sending is detected.
10. The apparatus of claim 7, further comprising:
the judging module is used for judging whether the source address of the second data packet is matched with the client address and the port when the connecting socket receives the second data packet;
and the sending module is used for sending the second data packet to the monitoring socket when the source address of the second data packet is not matched with the address and the port of the client.
11. The apparatus of claim 7, further comprising:
and the searching module is used for searching the monitoring socket and the data packet received by the connecting socket in a hash searching mode.
12. The apparatus of claim 7, wherein the binding operation is implemented by a connect function of a UDP protocol.
13. A terminal device, comprising:
one or more processors; and
one or more machine-readable media having instructions stored thereon that, when executed by the one or more processors, cause the terminal device to perform the method recited by one or more of claims 1-6.
14. One or more machine-readable media having instructions stored thereon, which when executed by one or more processors, cause the processors to perform the method recited by one or more of claims 1-6.
CN201811520003.2A 2018-12-12 2018-12-12 Data transmission method and connection device based on UDP (user Datagram protocol) Active CN111314273B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811520003.2A CN111314273B (en) 2018-12-12 2018-12-12 Data transmission method and connection device based on UDP (user Datagram protocol)

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811520003.2A CN111314273B (en) 2018-12-12 2018-12-12 Data transmission method and connection device based on UDP (user Datagram protocol)

Publications (2)

Publication Number Publication Date
CN111314273A CN111314273A (en) 2020-06-19
CN111314273B true CN111314273B (en) 2022-06-07

Family

ID=71161570

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811520003.2A Active CN111314273B (en) 2018-12-12 2018-12-12 Data transmission method and connection device based on UDP (user Datagram protocol)

Country Status (1)

Country Link
CN (1) CN111314273B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112261094B (en) * 2020-10-10 2023-07-21 厦门网宿有限公司 Message processing method and proxy server
CN112492054A (en) * 2020-11-05 2021-03-12 杭州萤石软件有限公司 Multiplexing method, device and equipment for UDP (user Datagram protocol) port
CN112631788B (en) * 2021-01-06 2023-11-28 上海哔哩哔哩科技有限公司 Data transmission method and data transmission server

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20070057640A (en) * 2005-12-01 2007-06-07 한국전자통신연구원 Apparatus for tcp and udp socket search
CN101272402A (en) * 2008-05-14 2008-09-24 深圳市同洲电子股份有限公司 Method, system and device for data transmission
CN103544324A (en) * 2013-11-11 2014-01-29 北京搜狐新媒体信息技术有限公司 Kernel-mode data access method, device and system
CN105337808A (en) * 2015-11-30 2016-02-17 网宿科技股份有限公司 Data transmission method, device and system
CN106506644A (en) * 2016-11-07 2017-03-15 深圳市共进电子股份有限公司 Terminal Debugging message collection method and system
CN108833469A (en) * 2018-04-27 2018-11-16 厦门理工学院 The resource transmission method, device and terminal device of a kind of terminal to terminal

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20070057640A (en) * 2005-12-01 2007-06-07 한국전자통신연구원 Apparatus for tcp and udp socket search
CN101272402A (en) * 2008-05-14 2008-09-24 深圳市同洲电子股份有限公司 Method, system and device for data transmission
CN103544324A (en) * 2013-11-11 2014-01-29 北京搜狐新媒体信息技术有限公司 Kernel-mode data access method, device and system
CN105337808A (en) * 2015-11-30 2016-02-17 网宿科技股份有限公司 Data transmission method, device and system
CN106506644A (en) * 2016-11-07 2017-03-15 深圳市共进电子股份有限公司 Terminal Debugging message collection method and system
CN108833469A (en) * 2018-04-27 2018-11-16 厦门理工学院 The resource transmission method, device and terminal device of a kind of terminal to terminal

Also Published As

Publication number Publication date
CN111314273A (en) 2020-06-19

Similar Documents

Publication Publication Date Title
CN111314273B (en) Data transmission method and connection device based on UDP (user Datagram protocol)
WO2021121370A1 (en) Message loss detection method and apparatus for message queue
EP3000217B1 (en) Electronic device using logical channels for communication
US20150067146A1 (en) Custom correlation of a distributed business transaction
CN108924274B (en) Domain name system DNS processing method and device, storage medium and electronic equipment
WO2022007406A1 (en) K8s-based service deployment method, apparatus, device, and medium
CN110933075B (en) Service calling method and device, electronic equipment and storage medium
CN108965359B (en) Communication method, communication device, readable medium, and electronic apparatus
CN109451354B (en) Terminal and method for awakening same
JP2011029896A (en) Remote starting system and method for the same
Yao et al. Design and implementation of IOT gateway based on embedded μTenux operating system
CN104570967B (en) Long-range control method and system based on android system
CN111338673B (en) Equipment debugging method and device, electronic equipment and storage medium
CN112948551A (en) Log obtaining method and device, computer equipment and storage medium
CN116881040A (en) Service operation processing method and device, electronic device and storage medium
CN107197088A (en) Screenshot method and device based on Android mobile device
CN111741087A (en) Remote upgrading method, terminal equipment and readable storage medium
CN108228880B (en) Method, device, equipment and medium for database management system to call external function
CN105608755A (en) Electronic sign-in method and system based on mobile terminal
CN112416641B (en) Method for detecting restarting of controlled end node in master-slave architecture and master control end node
CN114185804A (en) Interface testing method and device and terminal equipment
CN112597022A (en) Remote diagnosis method, device, storage medium and electronic equipment
CN113138814A (en) Remote assistance method, device, equipment and storage medium
WO2018082104A1 (en) Assisted positioning data sharing method, and terminal
TWI791316B (en) Method and system for implementing inter-process communications

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant