in Computer Networks edited by
9,649 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}$
in Computer Networks edited by
9.6k views

1 comment

1
1

4 Answers

37 votes
37 votes
Best answer

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 Comments

4
4
@bad doctor

This topic is still in syllabus of GATE 2021.

Source: https://gatecse.in/gate-2021-syllabus-including-changes/
0
0

Vikrant+Singh

Thanks :)

0
0
9 votes
9 votes

recv function same  as read()

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