Method for improving UDP (user Datagram protocol) sending efficiency of transmission system
Technical Field
The invention relates to the field of file transmission, in particular to a method for improving UDP sending efficiency of a transmission system.
Background
In a general operating system, such as Windows, Linux, MacOS, Android, and other systems, the process of sending a TCP message is as follows: the method comprises the steps that a socket () - > connect () interface of a client side establishes connection, then a recv () interface and a send () interface are called to receive and send, a socket () - > bind () - > accept () interface of a server establishes connection, and then the recv () interface and the send () interface are called to receive and send; the process of sending the UDP message is as follows: the Socket () interface of the transmission client establishes Socket, then calls a recvfrom () interface and a sendto () interface to receive and send, the Socket () - > bind () interface of the transmission server establishes connection, and then calls the recvfrom () interface and the sendto () interface to receive and send. From the sending process of the TCP message and the UDP message, the difference between the general UDP socket call and the TCP socket call can be found, because the UDP is a connectionless system, the process of establishing connection is eliminated, and therefore, the recv () interface and the send () interface can not be used for receiving and sending the message; the UDP packet can be sent only by carrying a destination address parameter on the sendto () interface to specify the destination of the transmission. Since the destination addresses of the sendto () interfaces are different each time, when UDP messages are sent, each message needs to be selected for the destination address, which causes additional performance loss, especially when communication is between two points, such as between a computer a and a computer B, such loss causes the UDP message sending efficiency to be low.
Accordingly, the prior art is deficient and needs improvement.
Disclosure of Invention
The invention aims to overcome the defects of the prior art, provides a method for improving UDP sending efficiency of a transmission system, and solves the problem of low sending efficiency caused by the fact that each message needs to be subjected to destination address selection when UDP messages are sent between two points in the prior art.
The technical scheme of the invention is as follows: a method for improving UDP transmission efficiency of a transmission system comprises the following steps:
step 100: and the transmission client calls a first socket () interface to establish a first socket.
Step 200: and the transmission client calls the connect () interface, sets a destination address and establishes the connection of the UDP socket.
Step 300: and the transmission server calls a second socket () interface to establish a second socket.
Step 400: the transmission server side calls a bind () interface to bind a local address and a port of the transmission server side; the destination address and the local address are the same address.
Step 500: the transmission client calls the send () interface to send the first UDP message, and the transmission server calls the recvdrom () interface to receive the first UDP message.
Step 600: and the transmission server judges whether the transmission server accords with the expected transmission client of the transmission server according to the transmission client transmission information acquired by the recvfrom () interface.
Step 700: if the transmission client-side is in line with the expected transmission client-side of the transmission server-side, the transmission server-side calls the connect () interface to obtain the address of the transmission client-side as the address of the opposite terminal, and the UDP socket enters the connected state.
Step 800: and the transmission client calls a send () interface to send the UDP message or calls a recv () interface to receive the UDP message. The transmission client calls a first socket () interface to establish a first socket, after calling a connect () interface, the transmission client sets a destination address of a UDP message for the first UDP message, the destination address is a local address of the transmission server, the transmission server calls a second socket () interface to establish a second socket, a bind () interface is called, the local address and the port of the transmission server are bound, the transmission client calls a send () interface to send the first UDP message to the transmission server, the transmission server calls a reveom () interface to receive the first UDP message, then transmission information of the transmission client is obtained, whether the transmission client is in accordance with an expected transmission client is judged according to the transmission information, if the transmission client is in accordance with the expected transmission client, the connection () interface is called by the transmission server as an opposite end address when the transmission server sends the UDP message to the transmission client, the UDP socket enters a connected connection state, and the transmission server and the transmission client enter the connected connection state, after connection, the transmission server side and the transmission client side can receive and send UDP messages, in the transmission process, only the sending destination address of the first UDP message needs to be selected, the UDP messages can be directly sent after the transmission client side and the transmission server side enter a connection state, the selection of the sending destination address is not needed when each UDP message is sent, and the sending efficiency of the UDP messages is effectively improved; the transmission client only needs to select the destination address for sending the first 1-2 UDP messages, and the subsequent UDP messages can be directly sent through the destination address connected with the UDP socket, so that the sending efficiency can be improved by 10-20%.
Further, the transmission information of the transmission client is address information of the transmission client and the content of the first UDP packet.
Further, the step 600 further comprises the steps of:
step 601: and the transmission server acquires the address information of the transmission client and the content of the first UDP message according to the recvdrom () interface.
Step 602: and judging whether the transmission client side accords with an expected transmission client side of the transmission server.
Step 603: if not, discarding the first UDP message, and the transmission client and the transmission server do not establish connection.
Step 604: if so, go to step 700. The recvfrom () interface receives the first UDP packet sent by the transmission client, acquires the address information of the transmission client and the content of the first UDP packet, determines whether the transmission client conforms to the expected transmission client of the transmission server according to the address information of the transmission client and the content of the first UDP packet, discards the first UDP packet if the transmission client does not conform to the expected transmission client of the transmission server, and stops the connection between the transmission client and the transmission server, if the transmission client conforms to the expected transmission client of the transmission server, the process may directly proceed to step 700.
Further, the step 800 further comprises the steps of:
step 801: and the transmission client calls the send () interface to send the UDP message to the transmission server.
Step 802: and the transmission service terminal calls a recvdrom () interface to receive the UDP message.
Step 803: and the transmission server side calls a sendto () interface to send the UDP message to the transmission client side.
Step 804: and the transmission client calls a recv () interface to receive the UDP message. After the transmission client side is connected with the transmission server side, when the transmission client side sends a UDP message to the transmission server side, the transmission client side calls a send () interface to send the UDP message to the transmission server side, and the transmission server side calls a recvdrom () interface to receive the UDP message; when the transmission server sends the UDP message to the transmission client, the transmission server calls the sendto () interface to send the UDP message to the transmission client, and the transmission client calls the recv () interface to receive the UDP message, so that the transmission client and the transmission server send and receive the UDP message.
Further, the communication mode between the transmission client and the transmission server is point-to-point communication.
Further, in step 603, the transmission client does not establish a connection with the transmission server, the connection process is ended, the transmission client uses the next UDP packet of the first UDP packet as the new first UDP packet, and the steps 100 to 800 are repeated. When the transmission client does not accord with the expected transmission client of the transmission server, the transmission client does not establish connection with the transmission server, the connection process is finished, at the moment, the transmission client uses the next UDP message as a new first UDP message, the step 100-step 800 is repeated, namely, a new destination address needs to be input, the first UDP message is sent with the new transmission server until the transmission client accords with the expected transmission client of the corresponding transmission server, generally, the destination address is selected for the first 1-2 UDP messages, namely, the operation of the step 100-step 800 needs to be repeated for 1-2 times, and the connection can be established between the transmission client and the transmission server.
By adopting the scheme, the invention provides a method for improving UDP sending efficiency of a transmission system, a first socket () interface is called by a transmission client to establish a first socket, after a connect () interface is called, a UDP message sending destination address is set for the first UDP message, the destination address is a local address of a transmission server, the transmission server calls a second socket () interface to establish a second socket, a bind () interface is called, the local address and the port of the transmission server are bound, the transmission client calls a send () interface to send the first UDP message to the transmission server, the transmission server calls a recfrom () interface to receive the first UDP message to obtain transmission information of the transmission client, and judges whether the transmission server accords with an expected transmission client according to the transmission information, if so, the connect () interface is called by the transmission server to serve as an opposite end address when the transmission server and the transmission client send the UDP message, the UDP socket enters a connected connection state, the transmission server and the transmission client enter the connected connection state, and after connection, the transmission server and the transmission client can receive and send UDP messages; the transmission client only needs to select the destination address for sending the first 1-2 UDP messages, and the subsequent UDP messages can be directly sent through the destination address connected with the UDP socket, so that the sending efficiency can be improved by 10-20%.
Drawings
FIG. 1 is a block flow diagram of the present invention;
FIG. 2 is a flowchart illustrating a method for determining whether a transmitting client is compliant with an expected transmitting client of a transmitting server;
fig. 3 is a flowchart of UDP packet transmission between the transmission client and the transmission server.
Detailed Description
The invention is described in detail below with reference to the figures and the specific embodiments.
Referring to fig. 1, the present invention provides a method for improving UDP sending efficiency in a transmission system, including the following steps:
step 100: and the transmission client calls a first socket () interface to establish a first socket.
Step 200: and the transmission client calls the connect () interface, sets a destination address and establishes the connection of the UDP socket.
Step 300: and the transmission server calls a second socket () interface to establish a second socket.
Step 400: the transmission server side calls a bind () interface to bind a local address and a port of the transmission server side; the destination address and the local address are the same address.
Step 500: the transmission client calls the send () interface to send the first UDP message, and the transmission server calls the recvdrom () interface to receive the first UDP message.
Step 600: and the transmission server judges whether the transmission server accords with the expected transmission client of the transmission server according to the transmission client transmission information acquired by the recvfrom () interface.
Step 700: if the transmission client-side is in line with the expected transmission client-side of the transmission server-side, the transmission server-side calls the connect () interface to obtain the address of the transmission client-side as the address of the opposite terminal, and the UDP socket enters the connected state.
Step 800: and the transmission client calls a send () interface to send the UDP message or calls a recv () interface to receive the UDP message. The transmission client calls a first socket () interface to establish a first socket, after calling a connect () interface, the transmission client sets a destination address of a UDP message for the first UDP message, the destination address is a local address of the transmission server, the transmission server calls a second socket () interface to establish a second socket, a bind () interface is called, the local address and the port of the transmission server are bound, the transmission client calls a send () interface to send the first UDP message to the transmission server, the transmission server calls a reveom () interface to receive the first UDP message, then transmission information of the transmission client is obtained, whether the transmission client is in accordance with an expected transmission client is judged according to the transmission information, if the transmission client is in accordance with the expected transmission client, the connection () interface is called by the transmission server as an opposite end address when the transmission server sends the UDP message to the transmission client, the UDP socket enters a connected connection state, and the transmission server and the transmission client enter the connected connection state, after connection, the transmission server side and the transmission client side can receive and send UDP messages, in the transmission process, only the sending destination address of the first UDP message needs to be selected, the UDP messages can be directly sent after the transmission client side and the transmission server side enter a connection state, the selection of the sending destination address is not needed when each UDP message is sent, and the sending efficiency of the UDP messages is effectively improved; the transmission client only needs to select the destination address for sending the first 1-2 UDP messages, and the subsequent UDP messages can be directly sent through the destination address connected with the UDP socket, so that the sending efficiency can be improved by 10-20%.
The transmission client side transmission information is address information of the transmission client side and first UDP message content.
Referring to fig. 2, the step 600 further includes the following steps:
step 601: and the transmission server acquires the address information of the transmission client and the content of the first UDP message according to the recvdrom () interface.
Step 602: and judging whether the transmission client side accords with an expected transmission client side of the transmission server.
Step 603: if not, discarding the first UDP message, and the transmission client and the transmission server do not establish connection.
Step 604: if so, go to step 700. The recvfrom () interface receives the first UDP packet sent by the transmission client, acquires the address information of the transmission client and the content of the first UDP packet, determines whether the transmission client conforms to the expected transmission client of the transmission server according to the address information of the transmission client and the content of the first UDP packet, discards the first UDP packet if the transmission client does not conform to the expected transmission client of the transmission server, and stops the connection between the transmission client and the transmission server, if the transmission client conforms to the expected transmission client of the transmission server, the process may directly proceed to step 700.
Referring to fig. 3, the step 800 further includes the following steps:
step 801: and the transmission client calls the send () interface to send the UDP message to the transmission server.
Step 802: and the transmission service terminal calls a recvdrom () interface to receive the UDP message.
Step 803: and the transmission server side calls a sendto () interface to send the UDP message to the transmission client side.
Step 804: and the transmission client calls a recv () interface to receive the UDP message. After the transmission client side is connected with the transmission server side, when the transmission client side sends a UDP message to the transmission server side, the transmission client side calls a send () interface to send the UDP message to the transmission server side, and the transmission server side calls a recvdrom () interface to receive the UDP message; when the transmission server sends the UDP message to the transmission client, the transmission server calls the sendto () interface to send the UDP message to the transmission client, and the transmission client calls the recv () interface to receive the UDP message, so that the transmission client and the transmission server send and receive the UDP message.
And the communication mode between the transmission client and the transmission server is point-to-point communication.
In step 603, the transmission client does not establish a connection with the transmission server, the connection process is ended, the transmission client uses the next UDP packet of the first UDP packet as a new first UDP packet, and the steps 100 to 800 are repeated. When the transmission client does not accord with the expected transmission client of the transmission server, the transmission client does not establish connection with the transmission server, the connection process is finished, at the moment, the transmission client uses the next UDP message as a new first UDP message, the step 100-step 800 is repeated, namely, a new destination address needs to be input, the first UDP message is sent with the new transmission server until the transmission client accords with the expected transmission client of the corresponding transmission server, generally, the destination address is selected for the first 1-2 UDP messages, namely, the operation of the step 100-step 800 needs to be repeated for 1-2 times, and the connection can be established between the transmission client and the transmission server.
In summary, the present invention provides a method for improving UDP sending efficiency of a transmission system, which includes establishing a first socket by a transmission client calling a first socket () interface, setting a UDP packet sending destination address for the first UDP packet after calling a connect () interface, the destination address being a local address of a transmission server, the transmission server calling a second socket () interface to establish a second socket, calling a bind () interface, binding the local address and a port of the transmission server, the transmission client calling a send () interface to send the first UDP packet to the transmission server, the transmission server calling a revfrom () interface to receive the first UDP packet, obtaining transmission information of the transmission client, and determining whether the transmission client is in line with an expected transmission client according to the transmission information, if so, calling the connect () interface as an opposite end address when the transmission server and the transmission client send the UDP packet, the UDP socket enters a connected connection state, the transmission server and the transmission client enter the connected connection state, and after connection, the transmission server and the transmission client can receive and send UDP messages; the transmission client only needs to select the destination address for sending the first 1-2 UDP messages, and the subsequent UDP messages can be directly sent through the destination address connected with the UDP socket, so that the sending efficiency can be improved by 10-20%.
The present invention is not limited to the above preferred embodiments, and any modifications, equivalent substitutions and improvements made within the spirit and principle of the present invention should be included in the protection scope of the present invention.