The UDP connection calls the Connect () function

Source: Internet
Author: User

UDP is a non-connected protocol that does not have anything like EOF in TCP.
8.11 UDP's Connect function asynchronous errors are not backed up to a UDP socket unless the socket is connected. We can actually call connect for the UDP socket, but the result is different from the TCP connection and there is no three-way handshake process. The kernel simply checks to see if there is an immediate error, logs the IP address and port number of the peer, and then immediately returns to the calling process.
for a UDP socket that is connected, three changes have occurred compared to the default non-connected UDP socket. (1) We can no longer specify the destination IP address and port number for the output operation. That is, instead of using sendto, we use write or send instead. Any content written to a connected UDP socket is automatically sent to the protocol address specified by connect. You can call SendTo to a connected UDP socket, but you cannot specify a destination address. The fifth argument of sendto must be a null pointer, and the sixth parameter should be 0. (2) instead of using recvfrom to learn about the sender of the datagram, use read, recv, or recvmsg instead. On a connected UDP socket, the datagram returned by the kernel for an input operation is only those datagrams from the Connect specified protocol address. This restricts a connected UDP socket to be able to exchange datagrams with only one peer. (3) asynchronous errors raised by a connected UDP socket are returned to the process they are in, and the non-connected UDP socket does not receive any asynchronous errors. packets from any other IP address or disconnected datagram are not delivered to this connected socket because they either source IP address or source UDP port does not match the protocol address that the socket connects to. The UDP client process or server process can call connect only if it uses its own UDP socket to communicate with the identified unique peer. The call to connect is typically a UDP client, but some network applications have UDP servers that communicate TFTP with a single customer for a long time, in which case both the customer and the server may call connect. DNS provides an example of a DNS server process that typically handles client requests, so the server process cannot call connect.
8.11.1 call Connect multiple times for a UDP socket a process that has a connected UDP socket can call connect again for one of two purposes: Specify a new IP address and port number. Port sockets. to disconnect a UDP socket connection, call connect again to set the address family of the socket address structure to AF_UNSPEC.
Explicit connection sockets are more efficient when the application process knows that it wants to send multiple datagrams to the same destination address. Call connect after calling two write involves kernel execution 1 connecting Sockets 2 Output First datagram3 Output A second datagram
8.13UDP lack of flow controlUDP socket Receive bufferThe number of UDP datagrams queued to a particular socket by UDP is limited by the size of the socket receive buffer. You can modify this value using the SO_RCVBUF socket option.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The UDP connection calls the Connect () function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.