top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

the exact use of listen system call in socket-programming?

0 votes
485 views

is it for No of connection can be accepted?
or is it for no of client can be in queue while SFD is busy..?

i have kept 0 as an argument in listen, still it is taking 10 connection..
but if i remove listen then it is showing an error..

Can anybody please help in this?

Thanks in advance

posted May 11, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

You bind a socket to a IP Address and Port and server should listen on this for accepting the client connection. And for this purpose listen is used -

Syntax

int listen(int sockfd, int backlog);

socket is first created with socket system call, a willingness to accept incoming connections and 
a queue limit for incoming connections are specified with listen(), and then the connections are 
accepted with accept. The listen() call applies only to sockets of type SOCK_STREAM or SOCK_SEQPACKET.

The backlog parameter defines the maximum length the queue of pending connections may 
grow to. If a connection request arrives with the queue full the client may receive an error with 
an indication of ECONNREFUSED or, if the underlying protocol supports retransmission.
answer May 11, 2015 by Salil Agrawal
Similar Questions
+1 vote

Is it right that it is used to bind Port number with IP?
If it is, then What is the need of binding it? and Why it is not present in UDP?
And also, What is the use of listen(5) ?
Does it mean that server can be connected maximum to 5 client? or it means that if server is busy with other client then 5 more client can be in queue.?
and also, What is the use of select() ?
As far as i know it is used when we want to monitor continuously input/output for that particular file descriptor.
is it correct?
If yes, then why it is used only when accepting connection request from multiple client.?

+2 votes

For An Example:
I have Socket-Programming where server is connected to 5 clients and it continuously sends and receives to all the clients.
Now, If one of the client looses the network or in whatever the case one of the client fails then master will also fail and because of it all other client will also be failed.

+2 votes

As per my understanding Receive system calls will be a blocking call of the code... it will not go ahead unless it receives the response from client .. my question is how would i set time in that? i want my code should wait only for few seconds then it has to come out from that

+3 votes

I noticed that if I make a listening socket using SOCK_STREAM | SOCK_NONBLOCK, that the sockets I get after calling listener.accept() dont have the O_NONBLOCK flag set, but checking the result of gettimeout() on the same sockets gives me 0.0, which means they are non blocking. Why is this the case?

...