0% found this document useful (0 votes)
1 views4 pages

VTU Network Programming -2

The document outlines key concepts and functions related to network programming, including socket creation, address binding, connection handling, data transmission, and closing connections. It also covers client-side connections, socket options, I/O multiplexing, address conversion, network name resolution, and error handling. Additionally, it mentions UNIX domain sockets, non-blocking sockets, IPv6 support, and SCTP protocol, with an offer for practical code examples.

Uploaded by

smanjuravi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views4 pages

VTU Network Programming -2

The document outlines key concepts and functions related to network programming, including socket creation, address binding, connection handling, data transmission, and closing connections. It also covers client-side connections, socket options, I/O multiplexing, address conversion, network name resolution, and error handling. Additionally, it mentions UNIX domain sockets, non-blocking sockets, IPv6 support, and SCTP protocol, with an offer for practical code examples.

Uploaded by

smanjuravi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

5/27/25, 7:13 AM VTU Network Programming Questions

1. Socket Creation and Types


➤ socket(domain, type, protocol)
Creates a new socket.
domain : Address family (e.g., AF_INET , AF_INET6 )

type : SOCK_STREAM (TCP), SOCK_DGRAM (UDP)

protocol : Usually set to 0 (default protocol for type)

Example:

c Copy Edit

int sockfd = socket(AF_INET, SOCK_STREAM, 0); // TCP socket

🔹 2. Address Binding
➤ bind(sockfd, addr, addrlen)
Assigns a local protocol address to a socket.
Example:

c Copy Edit

struct sockaddr_in servaddr; bind(sockfd, (struct sockaddr *)&servaddr,


sizeof(servaddr));

🔹 3. Connection Handling (TCP)


➤ listen(sockfd, backlog)
Marks the socket as passive for accepting connections.

➤ accept(sockfd, addr, addrlen)


Accepts a connection request and returns a new socket for communication.

https://chatgpt.com/c/68351653-3f10-8010-a055-130ce32b3968 1/4
5/27/25, 7:13 AM VTU Network Programming Questions

🔹 4. Data Transmission
➤ read() / recv()
Reads data from a socket.

➤ write() / send()
Sends data to a socket.

➤ recvfrom() / sendto() (UDP)


Used for datagram sockets.

🔹 5. Closing a Connection
➤ close(sockfd)
Closes the socket.

➤ shutdown(sockfd, how)
Shuts down part of a full-duplex connection.

🔹 6. Client-Side Connections
➤ connect(sockfd, addr, addrlen)
Initiates a connection to a remote socket.

🔹 7. Socket Options
➤ setsockopt() / getsockopt()
Configures socket behavior (timeouts, buffer sizes, etc.)
Example:

c Copy Edit

https://chatgpt.com/c/68351653-3f10-8010-a055-130ce32b3968 2/4
5/27/25, 7:13 AM VTU Network Programming Questions

int opt = 1; setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));

🔹 8. Multiplexing I/O
Allows a program to monitor multiple sockets.
select() : Monitors read/write/exception status

poll() : Scalable alternative to select()

epoll() : Linux-specific scalable I/O

🔹 9. Socket Address Conversion


➤ inet_pton() / inet_ntop()
Convert IP addresses between text and binary formats.

🔹 10. Network Name and Service Resolution


➤ getaddrinfo() / freeaddrinfo()
Modern, protocol-independent replacement for gethostbyname() and getservbyname() .

🔹 11. UNIX Domain Sockets


Used for inter-process communication (IPC) on the same host.
Uses AF_UNIX address family
Faster than IP-based sockets due to no network stack traversal

🔹 12. Non-blocking and Asynchronous Sockets


➤ fcntl() or ioctl()
https://chatgpt.com/c/68351653-3f10-8010-a055-130ce32b3968 3/4
5/27/25, 7:13 AM VTU Network Programming Questions

Set socket to non-blocking mode.


Used in event-driven programming to avoid blocking the application.

🔹 13. Error Handling


Most socket calls return -1 on error.
Use perror() or strerror(errno) to get human-readable error messages.

🔹 14. IPv6 and Protocol Independence


Use AF_INET6 and sockaddr_in6
Use getaddrinfo() to write address family–independent code
Supports dual-stack sockets (bind to :: )

🔹 15. SCTP (Stream Control Transmission Protocol)


Message-oriented like UDP, but reliable like TCP
Supports multihoming and multistreaming
Functions: sctp_sendmsg() , sctp_recvmsg() , etc.

Want Practical Code Examples?


I can give you full examples like:
TCP echo server/client
UDP client/server
Non-blocking select() -based multiplexing
SCTP client/server

https://chatgpt.com/c/68351653-3f10-8010-a055-130ce32b3968 4/4

You might also like