Extensive_Network_Programming_Guide
Extensive_Network_Programming_Guide
5. **Why is the socket address size passed as a value-result argument in accept()?** [2 marks]
- This allows the kernel to update the actual address length of the connected client dynamically.
15. **Explain the socket functions with code snippets.** [12 marks]
- **socket()** - Creates a socket.
```c
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
```
- **bind()** - Binds the socket to an address.
```c
bind(sockfd, (struct sockaddr*)&server_addr, sizeof(server_addr));
```
- **listen()** - Puts the server in listening mode.
```c
listen(sockfd, 5);
```
- **accept()** - Accepts incoming client connections.
```c
int client_sock = accept(sockfd, (struct sockaddr*)&client_addr, &client_len);
```
17. **How do TCP and UDP handle data transmission differently?** [4 marks]
- TCP: Uses acknowledgments and retransmission to ensure reliability.
- UDP: Sends packets without waiting for acknowledgments.
18. **Explain the differences between active and passive sockets.** [3 marks]
- Active Socket: Initiates connections (e.g., client sockets).
- Passive Socket: Waits for incoming connections (e.g., server sockets).