简体   繁体   中英

How does Linux buffer datagram sockets?

As a personal project i'm attempting to engineer a network time sync protocol, using C. One thing that is really fazing me is my total lack of knowledge about how my kernel will buffer my udp packets. I want to make sure that packets will send exactly when i want them to, and not be buffered to a certain block size or whatever. I also want to know if the buffer how i can ensure the division between datagrams, as i have seen to way to do this yet. I have read through a good amount of Beej's Guide to Network Programming , but i haven't found anything there to help me.

EDIT: I understand how UDP itself works. I am only asking about the properties of the kernel socket interface.

If the packet sequence and/or the reception of all packet is a matter, then you need to implement a protocol, that is, the sender will send a packet and it will wait until it receives the ACK's packet (an acknowledge of reception) back from the receiver. If the sender does not received the ACK packet in a reasonable time it will resend the same packet. Also, in the packet's data you could include a packet ID, an integer which increments for every packet sent; with this ID you avoid packet duplication. This is how, roughly, the UDP packets flow.

UDP is NOT connection oriented, you don't have a connection between server and client, client sends packet and server receives them, without any guarantee they get there neither they get in the order they were sent. For connection oriented protocols consider the use of TCP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM