hernandez.sarah79
hernandez.sarah79 7d ago β€’ 0 views

Multiple choice questions on Python `socket` and network programming

Hey there! πŸ‘‹ Let's test your Python socket and network programming knowledge. I've put together a quick study guide and a practice quiz to help you ace it. Good luck! πŸ€
πŸ’» Computer Science & Technology
πŸͺ„

πŸš€ Can't Find Your Exact Topic?

Let our AI Worksheet Generator create custom study notes, online quizzes, and printable PDFs in seconds. 100% Free!

✨ Generate Custom Content

1 Answers

βœ… Best Answer
User Avatar
johnson.lori55 Dec 29, 2025

πŸ“š Quick Study Guide

  • 🌐 Sockets: Endpoints of a two-way communication link between two programs running on the network.
  • 🐍 `socket` Module: Python's built-in module for network communication.
  • 🏠 Address Families:
    • `AF_INET`: IPv4 addresses.
    • `AF_INET6`: IPv6 addresses.
  • πŸ“‘ Socket Types:
    • `SOCK_STREAM`: TCP (Transmission Control Protocol) – reliable, connection-oriented.
    • `SOCK_DGRAM`: UDP (User Datagram Protocol) – unreliable, connectionless.
  • πŸ”‘ Common Socket Functions:
    • `socket()`: Creates a socket object.
    • `bind()`: Binds a socket to an address (host and port).
    • `listen()`: Enables a server to accept connections.
    • `connect()`: Establishes a connection with a server.
    • `accept()`: Accepts a connection from a client.
    • `send()`: Sends data through the socket.
    • `recv()`: Receives data from the socket.
    • `close()`: Closes the socket.
  • πŸ”’ Ports: Numerical identifiers used to distinguish different network applications on a single device (e.g., HTTP: 80, HTTPS: 443).
  • πŸ”’ TCP Handshake (Three-Way Handshake): SYN, SYN-ACK, ACK – Establishes a reliable connection.

πŸ§ͺ Practice Quiz

  1. Which address family is used for IPv4 addresses in the Python `socket` module?
    1. `AF_UNIX`
    2. `AF_INET`
    3. `AF_BLUETOOTH`
    4. `AF_APPLETALK`
  2. Which socket type provides a reliable, connection-oriented communication?
    1. `SOCK_DGRAM`
    2. `SOCK_RAW`
    3. `SOCK_STREAM`
    4. `SOCK_RDM`
  3. What function is used to bind a socket to a specific address (host and port)?
    1. `connect()`
    2. `listen()`
    3. `bind()`
    4. `accept()`
  4. Which function is used by a server to listen for incoming connections?
    1. `connect()`
    2. `bind()`
    3. `listen()`
    4. `accept()`
  5. What is the purpose of the `accept()` function?
    1. To send data to a client.
    2. To receive data from a client.
    3. To establish a connection with a server.
    4. To accept a connection from a client.
  6. Which protocol is associated with `SOCK_DGRAM`?
    1. TCP
    2. UDP
    3. HTTP
    4. FTP
  7. What is the primary function of the `close()` method in socket programming?
    1. To send data.
    2. To receive data.
    3. To terminate the socket connection.
    4. To bind the socket to an address.
Click to see Answers
  1. B
  2. C
  3. C
  4. C
  5. D
  6. B
  7. C

Join the discussion

Please log in to post your answer.

Log In

Earn 2 Points for answering. If your answer is selected as the best, you'll get +20 Points! πŸš€