Linux SOCKET-UDP Link Pack

Source: Internet
Author: User
Tags get ip

Does the LINUX UDP socket01udp number binding error?

Will, prompt address is using, local no difference

UDP does not need to initiate links, do not know whether the connection is successful

Client's IP address and port number is not correct, the packet has been thrown out

But the IP is not correct by grasping the package tool

Can get network unreachable's gateway answer

Port is not correct

Can get the answer of the other host rejected Port (the port in the picture is wrong)

Is it successful to bind the port number again after the run is terminated?

OK! Because UDP is the unknown state of the packet,TCP is not, to wait for the handshake link Farewell indicates that it is empty can be disconnected, then tied , and UDP no link, only the package.

Blocking on UDP packets

Kill process on server side

The client has no response.

Kill process on client side

No response from the service side.

Summary: UDP link does not lock dead port number (no handshake process does not need to confirm farewell), kill any part of the other end no response (receive no signal) 02 blocking methods and non-blocking methods are no different

Because UDP to the network state is unknown, want to get error message, can only in the program to catch the gateway or the other host's refused package

Non-blocking method to connect the socket

03 Blocking method reads 20 bytes at a time

The read content is only 20 bytes, each time the first 20 bytes

Blocking method send 2 bytes//meaningless

Every time it's the first two bytes.

04 non-blocking Method method 20 bytes

Effects and blocking methods

Non-blocking method send 2 bytes//meaningless

Effects and blocking methods

Why is buffer length meaningless in UDP?

Adjusting buffers in UDP to ensure that the number of bytes is inherently worthless

Because the UDP packet itself is not guaranteed to be continuous, there is no guarantee of delivery (no direct reply refused) may be full buffer, it is possible to drop packets. So each package is a complete data

Dual-channel 05Server and client side

Other issues can UDP bind only one IP?

Yes, all my code is bound to the second IP (generally the first is the loopback IP, the second is the IP of the ENS33 network, directly using the previously written get IP list can be

Can I send and receive data between UDP servers?

Yes, UDP does not need to set up a listening link, there is no accept and connect relationship, the server and the client are equal bits, two servers can also pass UDP packets

Can the client port number in UDP be bound?

can be bound, but without the meaning of binding. None of the links exist, and the specified port is not able to receive any content.

UDP port number netstat can you see that?

Can't see. Tried countless times, only by grasping the bag tool to see the source and whereabouts of the package (Ip:port)

Does the client necessarily need connect? What's the difference without using connect?

For the server side there is no difference, for the client side, connect in their host to sockfd fixed a addr, so you can write recv and send directly without having to execute recvfrom and sendto each time. but it only affects the SOCKFD file and address family bindings in the kernel, the UDP protocol or the UDP protocol, and the transceiver does not have any difference .

Can I write full buffers in a continuous write? Is there a difference between blocking and non-blocking?

There's a difference! Blocking method is full of buffer direct error rebound, non-blocking has been contracted, the other side of the buffer is full of packets directly thrown not read

Can the UDP send and receive buffers be set?

Yes, setsockopt, but there is no value, the UDP packet itself is discontinuous, unless to accept a gigantic UDP packet, only to adjust the buffer, but UDP itself drops is not known, UDP packet also has no length indicator.

Linux SOCKET-UDP Link Pack

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.