Lec2 socketProgramming
Lec2 socketProgramming
ANSWERS:
Sure, here are the answers to the multiple-choice questions:
1. b) Concurrent server
2. c) s.bind()
3. c) Process the client request
4. a) TCP
5. b) More scalable
6. b) s.connect()
7. b) Communication channels
8. a) s.close()
9. b) High-Level Access
10. b) Family of protocols used for transport mechanisms
11. c) Connectionless
12. a) The type of protocol used within the domain and type
13. b) s.accept()
14. a) Identifies a network interface
15. b) s.connect()
16. b) Listener for incoming connections
17. c) TCP servers are connection-oriented, while UDP servers are connectionless.
18. a) s.recvfrom()
19. c) Defines the server's listening port
20. b) connection-oriented
21. a) Initiator of the connection
22. b) s.send()
23. c) Type
24. d) The type of communication between sockets
29. c) Connectionless
30. a) The type of protocol used within the domain and type
34. b) Listener for incoming connections
#
_____________________________________________________________________________________
_____
MCQ
1. Which model is commonly assumed in most networking applications?
a) Client-server
b) Peer-to-peer
c) Hybrid
d) Mesh
2. What is the primary purpose of a server in networking applications?
a) To provide data storage
b) To establish connections
c) To offer defined services to clients
d) To manage network traffic
3. What are the two main classes of servers based on their handling of client
requests?
a) Sequential and random
b) Iterative and concurrent
c) Primary and secondary
d) Static and dynamic
4. In an iterative server, what happens when step 2 takes a long time?
a) Clients are queued
b) Other clients are serviced concurrently
c) Server crashes
d) No other clients are serviced
5. What advantage does a concurrent server offer over an iterative server?
a) Higher security
b) Faster processing
c) Ability to handle multiple client requests concurrently
d) Lower resource consumption
6. How does a concurrent server handle client requests?
a) By queuing them
b) By processing them one by one
c) By spawning new servers
d) By rejecting them
7. What does each client essentially have in a concurrent server setup?
a) Its own processor
b) Its own server
c) Dedicated bandwidth
d) Virtual memory
8. What is a requirement for a concurrent server to service multiple clients
simultaneously?
a) Multi-threading support
b) Exclusive access to the network
c) High-speed processors
d) Dedicated RAM
9. Why are servers categorized instead of clients in networking?
a) Clients are easier to manage
b) Clients can handle multiple servers
c) Clients are unaware of server types
d) Servers are more numerous
10. As a general rule, which type of server is concurrent?
a) UDP
b) TCP
c) HTTP
d) FTP
11. Which type of server is typically iterative?
a) FTP
b) HTTP
c) TCP
d) UDP
12. What determines whether a server is categorized as iterative or concurrent?
a) Client's preference
b) Server's location
c) Server's processing speed
d) Server's handling of client requests
13. In a concurrent server model, what happens when a client request arrives?
a) It's queued for later processing
b) It's processed immediately
c) It's ignored
d) It's redirected to another server
14. Which server model is more scalable for handling multiple client requests?
a) Iterative
b) Concurrent
c) Sequential
d) Hybrid
15. What happens to a server in a concurrent model after it completes handling a
client request?
a) It waits for more requests
b) It spawns another server
c) It goes into sleep mode
d) It shuts down
16. What characteristic of the operating system determines how concurrent servers
handle client requests?
a) Kernel version
b) CPU speed
c) Memory capacity
d) Multiprogramming support
17. How does a concurrent server achieve concurrency in handling client requests?
a) By using multiple threads
b) By prioritizing certain clients
c) By rejecting some requests
d) By increasing network bandwidth
18. What distinguishes a concurrent server from an iterative server?
a) Number of clients served
b) Time taken for processing
c) Type of client requests handled
d) Handling of multiple requests simultaneously
19. Which factor primarily determines whether a server is categorized as iterative or
concurrent?
a) Network speed
b) Client location
c) Operating system support
d) Server hardware
20. Which server model is typically preferred for high-throughput applications?
a) Iterative
b) Concurrent
c) Peer-to-peer
d) Hybrid
21. What is the primary concern with an iterative server model?
a) Security vulnerabilities
b) Resource consumption
c) Server downtime
d) Handling time for client requests
22. How does a concurrent server improve responsiveness to client requests?
a) By reducing server load
b) By increasing network latency
c) By prioritizing certain clients
d) By servicing multiple clients simultaneously
23. What is the primary advantage of TCP servers over UDP servers?
a) Higher throughput
b) Lower latency
c) Improved reliability
d) Reduced overhead
24. In which scenario might a TCP server function as an iterative server?
a) High network traffic
b) Low resource availability
c) Limited client base
d) Intensive data processing
25. What aspect of client-server communication makes it difficult for clients to
distinguish between iterative and concurrent servers?
a) Port number
b) Network protocol
c) Server response time
d) Server location
26. Which server model is more suitable for handling sporadic client requests
efficiently?
a) Iterative
b) Concurrent
c) Hybrid
d) Peer-to-peer
27. What is a potential drawback of using a concurrent server model?
a) Increased latency
b) Higher resource consumption
c) Limited scalability
d) Reduced security
28. Which server model is better suited for real-time applications with strict latency
requirements?
a) Iterative
b) Concurrent
c) Peer-to-peer
d) Hybrid
29. What criterion is commonly used to determine whether a server should be
categorized as iterative or concurrent?
a) Server location
b) Client preference
c) Operating system support
d) Server's physical size
30. In which scenario might a UDP server function as a concurrent server?
a) Low network traffic
b) Real-time communication
c) Large file transfers
d) High reliability requirements
Answers:
Sure, here are the answers:
1. a) Client-server
2. c) To offer defined services to clients
3. b) Iterative and concurrent
4. d) No other clients are serviced
5. c) Ability to handle multiple client requests concurrently
6. c) By spawning new servers
7. b) Its own server
8. a) Multi-threading support
9. c) Clients are unaware of server types
10. b) TCP
11. d) UDP
12. d) Server's handling of client requests
13. b) It's processed immediately
14. b) Concurrent
15. d) It shuts down
16. d) Multiprogramming support
17. a) By using multiple threads
18. d) Handling of multiple requests simultaneously
19. c) Operating system support
20. b) Concurrent
21. d) Handling time for client requests
22. d) By servicing multiple clients simultaneously
23. c) Improved reliability
24. d) Intensive data processing
25. c) Server response time
26. b) Concurrent
27. b) Higher resource consumption
28. a) Iterative
29. c) Operating system support
30. b) Real-time communication
MCQ
1. What does the method `s.bind()` do in socket programming?
a) Initiates a connection with the client
b) Binds address to the socket
c) Puts the server into listening mode
d) Receives the UDP message
2. Which method puts the server into listening mode?
a) s.bind()
b) s.listen()
c) s.accept()
d) s.connect()
3. What does the method `s.accept()` do?
a) Closes the connection with the client
b) Sends the TCP message
c) Passively accepts the client connection
d) Actively starts the TCP server connection
4. Which method is used to actively start the TCP server connection on the client
side?
a) s.bind()
b) s.listen()
c) s.accept()
d) s.connect()
5. Which method is used to send TCP messages?
a) s.send()
b) s.recv()
c) s.close()
d) s.sendto()
6. What does the method `s.recv()` do?
a) Sends the TCP message
b) Receives the TCP message
c) Closes the connection with the client
d) Sends the UDP message
7. What is the purpose of the `s.close()` method?
a) Sends the TCP message
b) Receives the TCP message
c) Closes the connection with the client
d) Sends the UDP message
8. Which method is used to send UDP messages?
a) s.send()
b) s.recv()
c) s.close()
d) s.sendto()
9. What does the method `s.recvfrom()` do?
a) Sends the TCP message
b) Receives the TCP message
c) Closes the connection with the client
d) Receives the UDP message
10. Which type of access allows implementing protocols like HTTP, FTP, etc.?
a) Low-Level Access
b) High-Level Access
c) Protocol-Level Access
d) Socket-Level Access
11. What are sockets in network programming?
a) Endpoints of a unidirectional communication channel
b) Endpoints of a bidirectional communication channel
c) Endpoints of a multicast communication channel
d) Endpoints of a broadcast communication channel
12. Sockets can communicate within a process, between processes on the same
machine, or on different machines. What's the reason behind this?
a) Sockets use the same protocol for all types of communication
b) Sockets use different protocols for different types of communication
c) Sockets use different ports for different types of communication
d) Sockets use different addresses for different types of communication
13. What is the purpose of the "Domain" in socket programming?
a) It specifies the type of communication between sockets
b) It identifies the network interface
c) It determines the transport mechanisms used
d) It indicates the family of protocols used
14. Which of the following is NOT a valid domain in socket programming?
a) AF_INET
b) PF_INET
c) AF_UNIX
d) AF_TCP
15. What does the "Type" parameter signify in socket programming?
a) Type of communication between sockets
b) Type of network interface used
c) Type of transport protocol employed
d) Type of encryption used
16. The "Protocol" parameter in socket programming typically has what value?
a) Zero
b) One
c) Five
d) Ten
17. What does the "Port" parameter represent in socket programming?
a) Number of sockets available
b) Number of connections allowed
c) Number of packets transmitted
d) Port number the server listens for clients on
18. Which of the following is NOT a valid representation of a port in socket
programming?
a) Integer
b) String
c) Name of the service
d) Float
19. What does the "Hostname" parameter identify in socket programming?
a) Type of communication
b) Network interface
c) Transport protocol
d) Encryption algorithm
20. How many levels of access does Python provide for network programming?
a) One
b) Two
c) Three
d) Four
21. Which level of access in Python allows implementing client and server for both
connection-oriented and connectionless protocols?
a) Low-Level Access
b) High-Level Access
c) Medium-Level Access
d) Advanced-Level Access
22. Which level of access in Python allows implementing protocols like HTTP, FTP,
etc.?
a) Low-Level Access
b) High-Level Access
c) Medium-Level Access
d) Advanced-Level Access
23. In socket programming, what is the primary purpose of the bind() method?
a) Initiating a connection with the client
b) Assigning an address to the socket
c) Sending data over the network
d) Receiving incoming connections
24. What does the listen() method do in socket programming?
a) Establishes a connection with the client
b) Puts the server into listening mode
c) Sends data to the client
d) Receives data from the client
25. What action does the accept() method perform in socket programming?
a) Connects the server to the client
b) Closes the connection with the client
c) Passively accepts incoming client connections
d) Actively initiates a connection with the client
26. Which method is used to actively start the TCP connection on the client side?
a) bind()
b) listen()
c) accept()
d) connect()
27. What is the primary function of the connect() method in socket programming?
a) Accepting incoming connections from clients
b) Sending data to the server
c) Actively initiating a TCP connection with the server
d) Closing the connection with the server
Answers:
1. b) Binds address to the socket
2. b) s.listen()
3. c) Passively accepts the client connection
4. d) s.connect()
5. a) s.send()
6. b) Receives the TCP message
7. c) Closes the connection with the client
8. d) s.sendto()
9. d) Receives the UDP message
10. b) High-Level Access
11. b) Endpoints of a bidirectional communication channel
12. b) Sockets use different protocols for different types of communication
13. d) It indicates the family of protocols used
14. d) AF_TCP
15. a) Type of communication between sockets
16. a) Zero
17. d) Port number the server listens for clients on
18. d) Float
19. b) Network interface
20. b) Two
21. a) Low-Level Access
22. b) High-Level Access
23. b) Assigning an address to the socket
24. b) Puts the server into listening mode
25. c) Passively accepts incoming client connections
26. d) connect()
27. c) Actively initiating a TCP connection with the server
#
_____________________________________________________________________________________
_____
MCQ
1. What is socket programming primarily used for?
a) Sharing files between computers
b) Connecting two nodes on a network to communicate with each other
c) Encrypting data transmissions
d) Performing network diagnostics
2. Which socket typically forms the listener in socket programming?
a) Client socket
b) Server socket
c) Local socket
d) Remote socket
3. What role does the server play in socket programming?
a) It listens on a particular port
b) It reaches out to the client
c) It establishes the initial connection
d) It sends data to the client
4. What module can be used for socket programming in Python?
a) json
b) socket
c) requests
d) urllib
5. What action is taken after creating a socket object in socket programming?
a) Binding to a host and port
b) Reaching out to the server
c) Establishing a connection
d) Listening for incoming connections
6. What is the purpose of binding a server to a specified host and port?
a) To establish a connection with the client
b) To send data to the client
c) To receive data from the client
d) To specify where the server should listen for incoming connections
7. What does an empty string as the host parameter signify in socket programming?
a) It limits connections to the local machine only
b) It allows connections from any available interface
c) It restricts connections to a specific IP address
d) It prevents connections altogether
8. What does the port number represent in socket programming?
a) The number of connections allowed
b) The size of data packets transmitted
c) The maximum number of clients
d) The endpoint for connections from clients
9. What does it mean when the server is put into listening mode in socket
programming?
a) It actively reaches out to clients
b) It passively waits for incoming connections
c) It continuously sends data to clients
d) It closes all existing connections
10. What does the backlog parameter specify when putting the server into listening
mode?
a) The number of connections waiting if the server is busy
b) The maximum size of data packets allowed
c) The number of clients allowed to connect simultaneously
d) The timeout period for inactive connections
11. What action does the server take when a new connection is accepted?
a) It sends a thank you message to the client
b) It closes the existing connections
c) It establishes a secure connection with the client
d) It returns a new socket object representing the connection
12. What information does the tuple returned by `s.accept()` contain for IPv4
connections?
a) (Port, IP address)
b) (Host, Port)
c) (IP address, Host)
d) (Port, Client ID)
13. What is the distinction between the listening socket and the socket returned by
`s.accept()`?
a) They both represent the same connection
b) The listening socket sends data to the client
c) The listening socket is used to accept new connections, while the other is used
to communicate with the client
d) The listening socket is only used by the client
14. What happens after the server sends a thank you message to the connected
sockets?
a) The server goes into sleep mode
b) The server continues to listen for new connections
c) The server disconnects from all clients
d) The server shuts down
15. What is the standard address for loopback in socket programming?
a) 0.0.0.0
b) 255.255.255.255
c) 127.0.0.1
d) 192.168.1.1
16. What role does the client play in socket programming?
a) It listens on a particular port
b) It reaches out to the server
c) It forms the listener socket
d) It establishes the initial connection
17. What action does the client take after reaching out to the server in socket
programming?
a) It listens for incoming connections
b) It sends data to the server
c) It establishes a secure connection with the server
d) It closes all existing connections
19. What does the server typically do after accepting a connection from a client in
socket programming?
a) Sends data to the client
b) Waits for further instructions from the client
c) Shuts down the connection
d) Returns a new socket object representing the connection
20. What is the primary purpose of socket programming?
a) To establish secure connections between clients and servers
b) To enable communication between nodes on a network
c) To perform network diagnostics and troubleshooting
d) To encrypt data transmissions between clients and servers
Answers:
Sure, here are the answers to the questions:
1. When reserving a host and port for a socket object, what does passing an empty
string as the host parameter signify?
a) Allows incoming connections only from localhost
b) Allows incoming connections from any available interface
c) Restricts incoming connections to specific IP addresses
d) Prevents incoming connections entirely
2. In socket programming, what is the significance of binding a server to a host and
port?
a) Initiates communication with the client
b) Reserves resources for the server
c) Enables the server to accept incoming connections
d) Establishes a secure connection
3. What does the backlog parameter specify when putting the server into listening
mode?
a) Maximum number of connections the server can handle simultaneously
b) Maximum data size the server can receive
c) Number of sockets the server can create
d) Maximum duration the server can listen for incoming connections
4. In the context of socket programming, what is the role of the while loop?
a) Continuously sends data to clients
b) Accepts all incoming connections indefinitely
c) Manages server resources
d) Terminates the server
5. When a client connects to the server, what does the server receive from the
`accept()` function?
a) New socket object representing the server
b) New socket object representing the client connection
c) Port number of the client
d) Hostname of the client
6. Why is the socket object returned by `accept()` important in socket
programming?
a) It represents the server
b) It represents the client connection
c) It manages server resources
d) It is used for server authentication
7. What is the purpose of closing the connection after sending a message to the
client?
a) Prevents further communication with the client
b) Frees up server resources
c) Initiates communication with another client
d) Ensures data security
8. In the context of socket programming, what does the term "backlog" refer to?
a) Number of pending connections in the server's queue
b) Data transmitted from the server to the client
c) Number of retries attempted by the server
d) Time interval between successive connection attempts
9. Which address does 127.0.0.1 represent in socket programming?
a) Local network address
b) Broadcast address
c) Loopback address
d) Remote server address
10. What does the term "binding" mean in the context of socket programming?
a) Establishing a connection with a client
b) Associating a socket with a specific IP address and port
c) Encrypting data transmission
d) Initiating data transfer
11. Why is the server socket distinct from the socket returned by `accept()`?
a) The server socket handles incoming connections, while the latter handles
communication with a specific client.
b) Both sockets perform the same functions.
c) The server socket is used for client authentication, while the latter is used for
server authentication.
d) The server socket is created by the client, while the latter is created by the
server.
12. What happens if the backlog parameter is exceeded in `listen()`?
a) Incoming connections are queued until space is available.
b) Connection attempts are refused by the server.
c) Server resources are allocated dynamically.
d) Clients are assigned higher priority for connection.
13. What does the `send()` function do in socket programming?
a) Receives data from the client
b) Initiates a connection with the client
c) Sends data to the client
d) Closes the connection with the client
14. Which function is used to establish a connection with a client in socket
programming?
a) `accept()`
b) `bind()`
c) `connect()`
d) `listen()`
15. What information does the `bind()` function require in socket programming?
a) Hostname only
b) Port number only
c) Hostname and port number
d) Protocol version
16. What does the `listen()` function do in socket programming?
a) Sends data to clients
b) Puts the socket into listening mode for incoming connections
c) Receives data from clients
d) Closes the connection with the client
17. What does the `connect()` function do in socket programming?
a) Puts the socket into listening mode
b) Closes the connection with the client
c) Initiates a connection with a remote server
d) Sends data to the server
18. Which function is used to close a socket connection in socket programming?
a) `close()`
b) `shutdown()`
c) `disconnect()`
d) `terminate()`
19. Which type of address is represented by 127.0.0.1 in socket programming?
a) IPv4 address
b) IPv6 address
c) Broadcast address
d) Multicast address
20. What is the purpose of passing an empty string as the host parameter when
binding a socket?
a) Allows the server to listen for connections from any available interface
b) Restricts incoming connections to localhost only
c) Specifies the server's IP address
d) Prevents incoming connections from remote hosts
### MCQ 1
**What is the first step a concurrent server performs when handling client requests?
**
a) Start a new server process\
b) Wait for a client request to arrive\
c) Terminate the existing server\
d) Go back to the initial step
### MCQ 2
**What does a concurrent server do after receiving a client request?**
a) It sends a request to another server\
b) It terminates the existing process\
c) It starts a new server to handle the request\
d) It waits for another client request
### MCQ 3
**How does the new server handle the client's request?**
a) It processes a part of the request and then forwards it\
b) It handles the entire request from the client\
c) It terminates immediately\
d) It waits for another client request
### MCQ 4
**What typically happens after the new server completes handling the client's
request?**
a) It starts handling a new client's request\
b) It forwards the request to another server\
c) It terminates\
d) It waits for instructions from the main server
### MCQ 5
**What does the main server do after starting a new server to handle a client’s
request?**
a) It shuts down\
b) It waits for the current server to finish\
c) It goes back to waiting for the next client request\
d) It processes another part of the same request
### MCQ 6
**The new server created to handle a client's request is responsible for which of the
following?**
a) Only initiating the request\
b) Handling the entire request\
c) Distributing the request to other servers\
d) Logging the request and then terminating
### MCQ 7
**What determines how a concurrent server creates a new server to handle client
requests?**
a) The type of client request\
b) The underlying operating system\
c) The server's memory capacity\
d) The network speed
### MCQ 8
**What happens to the new server once it has completed handling a client’s
request?**
a) It remains idle for the next request\
b) It continues running indefinitely\
c) It terminates\
d) It merges with the main server
### MCQ 9
**What is the main advantage of a concurrent server in networking applications?**
a) It reduces the overall number of servers required\
b) It improves the efficiency by handling multiple requests simultaneously\
c) It simplifies the server code\
d) It decreases the complexity of client requests
### MCQ 10
**What action does a concurrent server perform after the new server terminates?**
a) It logs the request details\
b) It sends a confirmation to the client\
c) It goes back to waiting for a new client request\
d) It updates its configuration files