Log In
23 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. listen, accept, bind, recv
  2. bind, listen, accept, recv
  3. bind, accept, listen, recv
  4. accept, listen, bind, recv
in Computer Networks 3.8k views

4 Answers

30 votes
Best answer

Answer: (B)

Bind: Binds the socket to an address

Listen: Waits for connections to the socket

Accept: Accepts a connection to the socket 

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
short trick to remember this is BLAB: Bind, Listen, Accept, Begin
Is this still in syllabus?
7 votes

recv function same  as read()

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.

1 vote

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


Related questions

25 votes
4 answers
Which of the following socket API functions converts an unconnected active TCP socket into a passive socket? connect bind listen accept
asked Sep 28, 2014 in Computer Networks jothee 5k views
18 votes
5 answers
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 {} & \text{} & \text{Interface $0$} \\\hline\text {} & \text{} & \text{Interface $ ... i-a, ii-c, iii-e, iv-d i-a, ii-d, iii-b, iv-e i-b, ii-c, iii-d, iv-e i-b, ii-c, iii-e, iv-d
asked Feb 13, 2015 in Computer Networks jothee 5k views
37 votes
4 answers
In a connected graph, a bridge is an edge whose removal disconnects the graph. Which one of the following statements is true? A tree has no bridges A bridge cannot be part of a simple cycle Every edge of a clique with size $\geq 3$ is a bridge (A clique is any complete subgraph of a graph) A graph with bridges cannot have cycle
asked Feb 13, 2015 in Graph Theory jothee 4.7k views
43 votes
2 answers
Consider a processor with byte-addressable memory. Assume that all registers, including program counter (PC) and Program Status Word (PSW), are size of two bytes. A stack in the main memory is implemented from memory location $(0100)_{16}$ and it grows upward. The stack pointer (SP) points to ... , the value of the stack pointer is: $(016A)_{16}$ $(016C)_{16}$ $(0170)_{16}$ $(0172)_{16}$
asked Feb 13, 2015 in CO and Architecture jothee 6.3k views