You are developing a TCP client using the socket module. After calling socket.connect(), which method should be invoked to ensure all buffered data is transmitted to the server before closing the connection?
Trap 1: socket.sendall()
sendall is for sending data, not managing connection state shutdown.
Trap 2: socket.flush()
The socket object does not have a flush() method.
Trap 3: socket.close()
Close terminates the descriptor but does not guarantee orderly buffer flushing.
- A
socket.sendall()
Why wrong: sendall is for sending data, not managing connection state shutdown.
- B
socket.flush()
Why wrong: The socket object does not have a flush() method.
- C
socket.shutdown(socket.SHUT_WR)
SHUT_WR signals the end of transmission, flushing buffers before closure.
- D
socket.close()
Why wrong: Close terminates the descriptor but does not guarantee orderly buffer flushing.