Implementation of UDP Client-Server Communication using Sockets in C
Experiment
Implementation of UDP Client-Server Communication using Sockets in C
Aim
To implement a simple UDP client-server program for sending and receiving messages.
Objective
- To understand connectionless communication using UDP
- To implement message passing between client and server
- To compare UDP with TCP
Theory
What is UDP?
User Datagram Protocol (UDP) is a connectionless protocol:
- No connection establishment
- No guarantee of delivery
- Faster than TCP
- No ordering or retransmission
Key Difference from TCP
| Feature | TCP | UDP |
|---|---|---|
| Connection | Yes | No |
| Reliability | High | Low |
| Speed | Slower | Faster |
| Use Case | File transfer | Streaming, DNS |
Working of UDP
-
No
listen()oraccept() -
Data sent using
sendto() -
Data received using
recvfrom()
Algorithm
Server
- Create socket
- Bind socket to port
- Receive message from client
- Send response
- Close socket
Client
- Create socket
- Send message to server
- Receive response
- Close socket
๐ป Program
๐น Server Program (UDP in C)
๐น Client Program (UDP in C)
▶️ Compilation and Execution
Run:
-
Terminal 1 →
./server -
Terminal 2 →
./client
๐Output
Server
Client
Key Points
-
UDP is connectionless → no
connect() -
Uses:
-
sendto() -
recvfrom()
-
- Faster but unreliable
-
Suitable for:
- Video streaming
- Online gaming
- DNS
๐งพ Result
The UDP client-server communication was successfully implemented and messages were exchanged without establishing a connection.
This experiment demonstrates connectionless communication using UDP sockets and highlights its speed and simplicity compared to TCP.
Comments
Post a Comment