Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

listen(2) [bsd man page]

LISTEN(2)							System Calls Manual							 LISTEN(2)

NAME
listen - listen for connections on a socket SYNOPSIS
listen(s, backlog) int s, backlog; DESCRIPTION
To accept connections, a socket is first created with socket(2), a willingness to accept incoming connections and a queue limit for incom- ing connections are specified with listen(2), and then the connections are accepted with accept(2). The listen call applies only to sock- ets 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, the request may be ignored so that retries may succeed. RETURN VALUE
A 0 return value indicates success; -1 indicates an error. ERRORS
The call fails if: [EBADF] The argument s is not a valid descriptor. [ENOTSOCK] The argument s is not a socket. [EOPNOTSUPP] The socket is not of a type that supports the operation listen. SEE ALSO
accept(2), connect(2), socket(2) BUGS
The backlog is currently limited (silently) to 5. 4.2 Berkeley Distribution May 14, 1986 LISTEN(2)

Check Out this Related Man Page

LISTEN(2)						     Linux Programmer's Manual							 LISTEN(2)

NAME
listen - listen for connections on a socket SYNOPSIS
#include <sys/socket.h> int listen(int s, int backlog); DESCRIPTION
To accept connections, a socket is first created with socket(2), a willingness to accept incoming connections and a queue limit for incom- ing connections are specified with listen, and then the connections are accepted with accept(2). 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, the request may be ignored so that retries succeed. NOTES
The behaviour of the backlog parameter on TCP sockets changed with Linux 2.2. Now it specifies the queue length for completely established sockets waiting to be accepted, instead of the number of incomplete connection requests. The maximum length of the queue for incomplete sockets can be set using the tcp_max_syn_backlog sysctl. When syncookies are enabled there is no logical maximum length and this sysctl setting is ignored. See tcp(7) for more information. RETURN VALUE
On success, zero is returned. On error, -1 is returned, and errno is set appropriately. ERRORS
EADDRINUSE Another socket is already listening on the same port. EBADF The argument s is not a valid descriptor. ENOTSOCK The argument s is not a socket. EOPNOTSUPP The socket is not of a type that supports the listen operation. CONFORMING TO
Single Unix, 4.4BSD, POSIX 1003.1g draft. The listen function call first appeared in 4.2BSD. BUGS
If the socket is of type AF_INET, and the backlog argument is greater than the constant SOMAXCONN (128 in Linux 2.0 & 2.2), it is silently truncated to SOMAXCONN. Don't rely on this value in portable applications since BSD (and some BSD-derived systems) limit the backlog to 5. SEE ALSO
accept(2), connect(2), socket(2) BSD Man Page 1993-07-23 LISTEN(2)
Man Page

15 More Discussions You Might Find Interesting

1. Programming

Tcp Ip Server

i am programming a tcp_ip server which intends to listen permanently to a client . the client can disconnect and connect again and the server accept it(by this point it works).The problem is when the client lose connection without a disconnect command and my code can't get it and keeps waiting for... (4 Replies)
Discussion started by: massimo_ratti
4 Replies

2. UNIX for Advanced & Expert Users

Problems with connections

Hello everybody, Look, im having problems with connections from other server, i must recieve maximus 5 connections from the other server, when I run 'netstat -A | grep <THE_OTHER_SERVER_IP>' I can see how many connections I have already established, but when they open another connection, i mean... (8 Replies)
Discussion started by: Lestat
8 Replies

3. UNIX for Advanced & Expert Users

close_wait connections causing a server to hung

Hi Guys, Just wondering if anyone of you have been in a situation where you end up having around 100 close_wait connections and seems to me those connections are locking up resources/processes in the server so unless the server is rebooted those processes won't be released by the close_wait... (3 Replies)
Discussion started by: hariza
3 Replies

4. Programming

command line socket read utility

HI I have a messaging s/w daemon(TIBCO rvrd) provided by vendor which will accept connections from various clients and routes messages to the destinations. In order to route it internally uses two ports(one tcp adn one udp). I want to know on which port(tcp/udp) it is transmitting... (3 Replies)
Discussion started by: axes
3 Replies

5. AIX

All exisiting connections from AIX 5.3

Hi, In an AIX 5.3 machine, I want to know all existing network connections going out from the box. NETSTAT command will gove me all the active connections. I want all the connections (active or inactive). Is there any command or file that will give this ? (5 Replies)
Discussion started by: ajeeb
5 Replies

6. Shell Programming and Scripting

perl socket

Hello there: What is default value of listen if I, avoid init it on constructor. I need maximum num for Listen. I want to write a daemon thus i need unlimited listen. my $sock = IO::Socket::INET->new( Listen => 20, LocalPort => $port, Reuse => 1) Thanks in advance. (3 Replies)
Discussion started by: Zaxon
3 Replies

7. Programming

Problem with socket binding - "system" call

Hi, I am having an issue with using sockets. I have a program which binds to a socket and listen on it. Later I spawn a thread to handle some function. In the new thread created I need to call a shell script which executes the specified function. Here I am using a system command to call the... (5 Replies)
Discussion started by: Janardhanbr
5 Replies

8. UNIX for Advanced & Expert Users

how to find the queue size in listen system call

hi, I want to find the queue size of the listen system call which is defined as below listen(s, backlog) The backlog parameter sets the maximum number of outstanding connections which can be queued awaiting acceptance by the server. I want to know where is this... (2 Replies)
Discussion started by: sowjanya
2 Replies

9. Solaris

Established connections causing lag?

I'm not to sure how to go about this questions, so I will just ask it and then get criticized. How many Established connections should a V440 be able to support? (4 Replies)
Discussion started by: adelsin
4 Replies

10. Programming

Questions about sockets

Hello, the function listen creates a list that memorizes a number of incoming calls through a socket but how do the first call is deleted and the second becomes the first, is it done using accept? I have read that accept can wait if it finds no calls in the listen list ,is it the same with read... (7 Replies)
Discussion started by: fireblast
7 Replies

11. Programming

Handle int listen(int sockfd, int backlog) in TCP

Hi, from the manual listen(2): listen for connections on socket - Linux man page It has a parameter called backlog and it limits the maximum length of queue of pending list. If I set backlog to 128, is it means no more than 128 packets can be handled by server? If I have three... (3 Replies)
Discussion started by: sehang
3 Replies

12. Shell Programming and Scripting

To get Port number alone from the list

~]#netstat -vatn | grep LISTEN tcp 0 0 0.0.0.0:34895 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN ... (7 Replies)
Discussion started by: linuxadmin
7 Replies

13. Solaris

socket in listen state disappears/closes automatically

Hi, I am using solaris 10. I have opened a socket connection using java in solaris 10 operating system, the port went to LISTEN state and able to create new socket connection and the new connections went to ESTABLISHED state. If I issue the command "netstat -an | grep <<portnumber>>", I... (10 Replies)
Discussion started by: kumar3k
10 Replies

14. UNIX for Advanced & Expert Users

Checking concurrent SSHD connections

Hi Guys i am facing an issue when SSH connections are overflowing on my server, i get connections from thousands of servers, out of which few does not close them after sending a file. i want to pull some information about concurrent ssh connections i used "netstat -an | grep 22" i... (4 Replies)
Discussion started by: Prateek007
4 Replies

15. Shell Programming and Scripting

JAVA connections in Linux

(5 Replies)
Discussion started by: ajayram_arya
5 Replies