UDP is a connection less protocol. There is no connection is established between client and server. Creating Standard UDP Client/Server is discussed here
In UDP, the client does not form a connection with the server like in TCP and instead, It just sends a datagram. Similarly, the server need not to accept a connection and just waits for datagrams to arrive. We can call a function called connect() in UDP but it does not result anything like it does in TCP. There is no 3 way handshake. It just checks for any immediate errors and store the peer’s IP address and port number. connect() is storing peers address so no need to pass server address and server address length arguments in sendto().
Necessary Functions :
int connect(int sockfd, const struct sockaddr *servaddr, socklen_t addrlen); returns : 0 if OK -1 on error arguments : sockfd : File descriptor of socket to be connected. struct sockaddr *servaddr : server address structure. addrlen : length of server address structure.
Below is the implementation showing message transfer between server-client :
UDP Server code :
UDP Client code :
- TCP Server-Client implementation in C
- UDP Server-Client implementation in C
- Java Implementation of Deffi-Hellman Algorithm between Client and Server
- Embedding Tomcat Server in Maven Project
- What to do when load on a Linux based web server goes high?
- Implementation of ls | wc command
- Implementation of Locking in DBMS
- Implementation of a Falling Matrix
- Generic Implementation of QuickSort Algorithm in C
- Array implementation of queue (Simple)
- Binary Tree (Array implementation)
- Decision tree implementation using Python
- Bloom Filters - Introduction and Python Implementation
- Johnson’s algorithm for All-pairs shortest paths | Implementation
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.