edited by
9,612 views
27 votes
27 votes

Identify the correct order in which a server process must invoke the function calls accept, bind, listen, and recv according to UNIX socket API.

  1. $\textsf{listen, accept, bind, recv}$
  2. $\textsf{bind, listen, accept, recv}$
  3. $\textsf{bind, accept, listen, recv}$
  4. $\textsf{accept, listen, bind, recv}$
edited by

4 Answers

Best answer
37 votes
37 votes

Answer: (B)

$\textsf{Bind:}$ Binds the socket to an address

$\textsf{Listen:}$ Waits for connections to the socket

$\textsf{Accept:}$ Accepts a connection to the socket 

$\textsf{Recv:}$ Receives data from connection

From Man page of accept:

It extracts the first connection request on the queue of pending connections for the listening socket, creates a  new connected socket,  and returns a new file descriptor referring to that socket.  The newly created socket is not in the listening state. The original socket is unaffected by this call.

edited by
4 votes
4 votes

correct order in which a server process must invoke the function calls accept, bind, listen, and recv according to UNIX socket API will be

bind ->listen -> accept -> recv

First three function call will be used to connection establishment and recv function call is used to transfer data after successful connection establishment.

3 votes
3 votes

The sequence goes like this:-

  1. socket() or socket_init() — creates the socket.

     
  2. bind() — binds the local machine's IP address and port number to the socket.

     
  3. connect() — sends SYN packets (Client's perspective)
    listen() — waits for someone to send SYN packets (Server's perspective)
    accept() — sends ACK in response to SYN (Server's perspective)

     
  4. send() — sends data.

    recv() — receives data.

     

  5. close() — sends FIN packets to close the connection.

 

Option B

Answer:

Related questions

34 votes
34 votes
3 answers
1
go_editor asked Sep 28, 2014
11,128 views
Which of the following socket API functions converts an unconnected active TCP socket into a passive socket?$\textsf{connect}$$\textsf{bind}$$\textsf{listen}$$\textsf{acc...
26 votes
26 votes
5 answers
2
go_editor asked Feb 12, 2015
14,097 views
Consider the following routing table at an IP router:$$\begin{array}{|l|l|l|} \hline \textbf {Network No} & \textbf {Net Mask} & \textbf{Next Hop} \\\hline \text {128.96...