Question
Identify the correct order in which a server process must invoke the function calls accept, bind, listen, and recv according to UNIX socket API
Official answer and solution
- Official answer
- B
- From
- Official GATE 2015 answer key
Solution
Trace the lifecycle of a stream-oriented (TCP) server using the standard Berkeley UNIX sockets API.
A standard connection-oriented TCP server follows this execution sequence:
socket(): Create the socket endpoint.bind(): Associate the socket with a local IP address and port number.listen(): Place the socket in passive listening mode with a designated backlog queue for incoming connections.accept(): Block until an incoming client connection request arrives, returning a new connected socket descriptor.recv(): Receive data from the connected client socket.
Thus, the four specified function calls must be invoked in the order:
bind listen accept recv.
B
Calling listen() before bind(), or calling accept() before the socket has been put into listening state via listen().
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2015 Computer Science and Information Technology (CS) Session 2
- Question
- 30 of 65, printed as CS Q.20
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.