A simple implementation of client-server communication using C sockets, supporting both TCP and UDP protocols.
- TCP socket implementation
- Connection-oriented
- Reliable data delivery
- Stream-based communication
- UDP socket implementation
- Connectionless
- Faster, but unreliable
- Message-based communication
- Basic client-server communication
- Simple message exchange
- Error handling
Compile all programs:
make all
Or compile specific versions:
make tcp_server tcp_client # For TCP versions
make udp_server udp_client # For UDP versions
- Start the TCP server:
./tcp_server
- In another terminal, start the TCP client:
./tcp_client
- Start the UDP server:
./udp_server
- In another terminal, start the UDP client:
./udp_client
-
TCP (Transmission Control Protocol):
- Connection-oriented
- Reliable data delivery
- Order of messages guaranteed
- Better for applications requiring data integrity
-
UDP (User Datagram Protocol):
- Connectionless
- No guarantee of delivery or order
- Faster due to less overhead
- Better for real-time applications
Key differences between TCP and UDP implementations:
1. Socket Type:
- TCP uses `SOCK_STREAM`
- UDP uses `SOCK_DGRAM`
2. Connection Handling:
- TCP requires `connect()`, `accept()`, and maintains connection state
- UDP is connectionless, using `sendto()` and `recvfrom()` for each message
3. Message Boundaries:
- TCP is stream-based
- UDP preserves message boundaries
4. Reliability:
- TCP handles retransmission automatically
- UDP has no built-in reliability mechanisms