C++ Socket Programming Quiz

Sockets Programming is required skill for any developer working on network applications. This online quiz covers the basics of C++ Socket Programming.


@learncpp #Beginner 15 questions  

Stats

  • Average Time    4 minutes
  • Average Points 1 pts
  • Views       3 k
  • Featured Yes
  • Takers         267
  • Completed 429

Video based Quiz

Please watch the video and try to memorize the concepts before attempting the Quiz.

Notes for Quiz

  • Network concept of a "Socket" refers to the connection of one host to another through the combination of compatible IP addresses and ports.
  • Socket programming is generally referred to as low-level programming.
  • It takes form of client-server infrastructure.
  • Two Sockets must be of same type and in same domain to enable communication.
  • Structure of an application using sockets and events occurring are:
  • 1. Winsock Version
  • 2. SockAddr_In
  • struct sockaddr_in {
  • short sin_family;
  • unsigned short sin_port;
  • struct in_addr sin_addr;
  • char sin_zero[8];
  • };
  • sin_family : specifies address family
  • sin_port: specifies port number and must be used with htons()
  • sin_addr: holds the ip address returned by inet_addr()
  • sin_zero: used with char array, normally sets to 0
  • htons(): converts host byte order to network byte order
  • inet_addr(): takes string as argument and converts it into form used by socket connection
  • bind(): binds a socket to SocketAddr_In containing IP address and port to build connection
  • listen(): tells a socket to listen for an incoming connection
  • accepts() : waits for a connection and wakes when a connection is established.
  • connect(): connects a client to server which is in listening state and set to accept a connection
  • closesocket(): closes an open socket
  • Types of Sockets
  • 1. TCP
  • 2. Datagram Sockets
  • - TCP (Transmission Control Protocol) ensures the delivery of packets
  • - UDP (User Datagram Protocol) does not ensure the delivery of packets
  • Strategies for Implementing Servers
  • 1. Concurrent: Handles multiple clients simultaneously and creates socket for each client
  • 2. Single Process Concurrent Servers: Handles multiple clients simultaneously while maintaining multiple open connections and listening for messages for each one.
  • 3. Iterative Servers: Provides single message to a Client and opens only one socket at a time.

Related Quizzes



Loading Please Wait...