GATE | GATE-CS-2015 (Set 2) | Question 65
Identify the correct order in which a server process must invoke the function calls accept, bind, listen, and recv according to UNIX socket API.
(A) listen, accept, bind recv
(B) bind, listen, accept, recv
(C) bind, accept, listen, recv
(D) accept, listen, bind, recv
Answer: (B)
Explanation: bind, listen, accept and recv are server side socket API functions.
bind() associates a socket with a socket address structure, i.e. a specified local port number and IP address. listen() causes a bound TCP socket to enter listening state. accept() accepts a received incoming attempt to create a new TCP connection from the remote client, recv() is used to receive data from a remote socket.
A server must first do bind() to tell operating system the port number on which it would be listing, then it must listen to receive incoming connection requests on the bound port number. Once a connection comes, the server accepts using accept(), then starts receiving data using recv().
Quiz of this Question
Please Login to comment...