The Gateway to Computer Science Excellence
+20 votes
2.9k views

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 by Veteran (105k points) | 2.9k views
+1

4 Answers

+28 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

by Boss (33.9k points)
edited by
+25
short trick to remember this is BLAB: Bind, Listen, Accept, Begin
+13
0
Is this still in syllabus?
+2
+5 votes

recv function same  as read()

by Boss (12.3k points)
+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.

by Active (1.8k points)
0 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

by Loyal (6.2k points)
Answer:

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,257 answers
198,086 comments
104,735 users