UNIX Socket FAQ
About this FAQ
Size: 2 KB, Last Update:5 Nov 2001
About this FAQ
This FAQ is maintained by Vic Metcalfe ( vic@acm.org ), with lots o Who is this FAQ for?
Size: 1 KB, Last Update:5 Nov 2001
Who is this FAQ for?
This FAQ is for C programmers in the Unix environment. It is What are Sockets?
Size: 1 KB, Last Update:5 Nov 2001
What are Sockets?
Sockets are just like "worm holes" in science fiction. When thi How do Sockets Work?
Size: 1 KB, Last Update:5 Nov 2001
How do Sockets Work?
The implementation is left up to the vendor of your particula Where can I get source code for the book [book title]?
Size: 1 KB, Last Update:5 Nov 2001
Where can I get source code for the book [book title]?
Here is a list of the place Where can I get more information?
Size: 1 KB, Last Update:5 Nov 2001
Where can I get more information?
I keep a copy of the resources I know of on my s How can I tell when a socket is closed on the other end?
Size: 2 KB, Last Update:5 Nov 2001
How can I tell when a socket is closed on the other end?
From Andrew Gierth ( andr Why do I get EPROTO from read()?
Size: 1 KB, Last Update:5 Nov 2001
Why do I get EPROTO from read()?
From Steve Rago ( sar@plc.com ):
EPROTO mean How can I force a socket to send the data in its buffer?
Size: 8 KB, Last Update:5 Nov 2001
How can I force a socket to send the data in its buffer?
From Richard Stevens ( rs Where can a get a library for programming sockets?
Size: 1 KB, Last Update:5 Nov 2001
Where can a get a library for programming sockets?
There is the Simple Sockets Lib How come select says there is data, but read returns zero?
Size: 1 KB, Last Update:5 Nov 2001
How come select says there is data, but read returns zero?
The data that causes se Whats the difference between select() and poll()?
Size: 2 KB, Last Update:5 Nov 2001
Whats the difference between select() and poll()?
From Richard Stevens ( rstevens@ How do I send [this] over a socket?
Size: 1 KB, Last Update:5 Nov 2001
How do I send [this] over a socket?
Anything other than single bytes of data will How do I use TCP_NODELAY?
Size: 2 KB, Last Update:5 Nov 2001
How do I use TCP_NODELAY?
First off, be sure you really want to use it in the firs What exactly does the Nagle algorithm do?
Size: 1 KB, Last Update:5 Nov 2001
What exactly does the Nagle algorithm do?
It groups together as much data as it ca What is the difference between read() and recv()?
Size: 1 KB, Last Update:5 Nov 2001
What is the difference between read() and recv()?
From Andrew Gierth ( andrew@erle I see that send()/write() can generate SIGPIPE
Size: 1 KB, Last Update:5 Nov 2001
I see that send()/write() can generate SIGPIPE
checking for the EPIPE error? Are there an What's with the second parameter in bind()?
Size: 1 KB, Last Update:5 Nov 2001
What's with the second parameter in bind()?
The man page shows it as "struct socka After the chroot(), calls to socket() are failing
Size: 1 KB, Last Update:5 Nov 2001
After the chroot(), calls to socket() are failing
From Andrew Gierth ( andrew@erlenstar.d Why do I keep getting EINTR from the socket calls?
Size: 1 KB, Last Update:5 Nov 2001
Why do I keep getting EINTR from the socket calls?
This isn't really so much an er When will my application receive SIGPIPE?
Size: 1 KB, Last Update:5 Nov 2001
When will my application receive SIGPIPE?
From Richard Stevens ( rstevens@noao.edu What are socket exceptions? What is out-of-band data?
Size: 1 KB, Last Update:5 Nov 2001
What are socket exceptions? What is out-of-band data?
Unlike exceptions in C++, s running on? How can I find the full hostname (FQDN) of the
Size: 1 KB, Last Update:5 Nov 2001
running on? How can I find the full hostname (FQDN) of the
From Richard Stevens How do I get the port number for a given service?
Size: 1 KB, Last Update:5 Nov 2001
How do I get the port number for a given service?
Use the getservbyname() routine. If bind() fails, what should I do with the socket descriptor?
Size: 0 KB, Last Update:5 Nov 2001
If bind() fails, what should I do with the socket descriptor?
If you are exiting, How do I properly close a socket?
Size: 1 KB, Last Update:5 Nov 2001
How do I properly close a socket?
This question is usually asked by people who try When should I use shutdown()?
Size: 5 KB, Last Update:5 Nov 2001
When should I use shutdown()?
From Michael Hunter ( mphunter@qnx.com ):
shutd Please explain the TIME_WAIT state.
Size: 2 KB, Last Update:5 Nov 2001
Please explain the TIME_WAIT state.
Remember that TCP guarantees all data transmit Why does it take so long to detect that the peer died?
Size: 3 KB, Last Update:5 Nov 2001
Why does it take so long to detect that the peer died?
From Andrew Gierth ( andrew What are the pros/cons of select(), non-blocking I/O and SIGIO?
Size: 1 KB, Last Update:5 Nov 2001
What are the pros/cons of select(), non-blocking I/O and SIGIO?
Using non-blocking How do I convert a string into an internet address?
Size: 1 KB, Last Update:5 Nov 2001
How do I convert a string into an internet address?
If you are reading a host's ad How can my client work through a firewall/proxy server?
Size: 1 KB, Last Update:5 Nov 2001
How can my client work through a firewall/proxy server?
If you are running through Why does connect() succeed even before my server did an
Size: 1 KB, Last Update:5 Nov 2001
Why does connect() succeed even before my server did an
From Andrew Gierth ( and Why do I sometimes lose a server's address when using more than
Size: 2 KB, Last Update:5 Nov 2001
Why do I sometimes lose a server's address when using more than
From Andrew Gier How can I set the timeout for the connect() system call?
Size: 2 KB, Last Update:5 Nov 2001
How can I set the timeout for the connect() system call?
From Richard Stevens ( rs system choose one for me on the connect() call? Should I bind()
Size: 3 KB, Last Update:5 Nov 2001
system choose one for me on the connect() call? Should I bind()
From Andrew Gie Why do I get "connection refused" when the server isn't running?
Size: 1 KB, Last Update:5 Nov 2001
Why do I get "connection refused" when the server isn't running?
The connect() cal over the socket ? Is there a way to have a dynamic buffer ?
Size: 1 KB, Last Update:5 Nov 2001
over the socket ? Is there a way to have a dynamic buffer ?
ming
This questio How come I get "address already in use" from bind()?
Size: 1 KB, Last Update:5 Nov 2001
How come I get "address already in use" from bind()?
You get this when the address How should I choose a port number for my server?
Size: 1 KB, Last Update:5 Nov 2001
How should I choose a port number for my server?
The list of registered port assig What is the difference between SO_REUSEADDR and SO_REUSEPORT?
Size: 3 KB, Last Update:5 Nov 2001
What is the difference between SO_REUSEADDR and SO_REUSEPORT?
SO_REUSEADDR allows How can I write a multi-homed server?
Size: 3 KB, Last Update:5 Nov 2001
How can I write a multi-homed server?
The original question was actually from Shan How can I read only one character at a time?
Size: 2 KB, Last Update:21 Dec 2001
Writing Server Applications (TCP/SOCK_STREAM): How can I read only one character at a I'm trying to exec() a program from my server, and attach my
Size: 1 KB, Last Update:5 Nov 2001
I'm trying to exec() a program from my server, and attach my
If the program you Why don't my sockets close?
Size: 1 KB, Last Update:5 Nov 2001
Why don't my sockets close?
When you issue the close() system call, you are closin How can I make my server a daemon?
Size: 3 KB, Last Update:5 Nov 2001
How can I make my server a daemon?
There are two approaches you can take here. Th How can I listen on more than one port at a time?
Size: 1 KB, Last Update:5 Nov 2001
How can I listen on more than one port at a time?
The best way to do this is with What exactly does SO_REUSEADDR do?
Size: 1 KB, Last Update:5 Nov 2001
What exactly does SO_REUSEADDR do?
This socket option tells the kernel that even i What exactly does SO_LINGER do?
Size: 0 KB, Last Update:5 Nov 2001
What exactly does SO_LINGER do?
On some unixes this does nothing. On others, it i What exactly does SO_KEEPALIVE do?
Size: 1 KB, Last Update:5 Nov 2001
What exactly does SO_KEEPALIVE do?
From Andrew Gierth ( andrew@erlenstar.demon.co. How can I bind() to a port number < 1024?
Size: 1 KB, Last Update:5 Nov 2001
How can I bind() to a port number < 1024?
From Andrew Gierth ( andrew@erlenstar.de How do I get my server to find out the client's address / host-
Size: 1 KB, Last Update:5 Nov 2001
How do I get my server to find out the client's address / host-
From Andrew Gier When should I use UDP instead of TCP?
Size: 1 KB, Last Update:5 Nov 2001
When should I use UDP instead of TCP?
UDP is good for sending messages from one sy What is the difference between "connected" and "unconnected"
Size: 1 KB, Last Update:5 Nov 2001
What is the difference between "connected" and "unconnected"
From Andrew Gierth of the socket? Does doing a connect() call affect the receive
Size: 1 KB, Last Update:5 Nov 2001
of the socket? Does doing a connect() call affect the receive
From Richard Stev How can I read ICMP errors from "connected" UDP sockets?
Size: 1 KB, Last Update:5 Nov 2001
How can I read ICMP errors from "connected" UDP sockets?
If the target machine dis How can I be sure that a UDP message is received?
Size: 1 KB, Last Update:5 Nov 2001
How can I be sure that a UDP message is received?
You have to design your protocol How can I be sure that UDP messages are received in order?
Size: 1 KB, Last Update:5 Nov 2001
How can I be sure that UDP messages are received in order?
You can't. What you ca How often should I re-transmit un-acknowleged messages?
Size: 1 KB, Last Update:5 Nov 2001
How often should I re-transmit un-acknowleged messages?
The simplest thing to do i How come only the first part of my datagram is getting through?
Size: 2 KB, Last Update:5 Nov 2001
How come only the first part of my datagram is getting through?
This has to do wit Why does the socket's buffer fill up sooner than expected?
Size: 2 KB, Last Update:5 Nov 2001
Why does the socket's buffer fill up sooner than expected?
From Paul W. Nelson ( n How would I put my socket in non-blocking mode?
Size: 1 KB, Last Update:5 Nov 2001
How would I put my socket in non-blocking mode?
From Andrew Gierth ( andrew@erlens How can I put a timeout on connect()?
Size: 2 KB, Last Update:5 Nov 2001
How can I put a timeout on connect()?
Andrew Gierth ( andrew@erlenstar.demon.co.uk Sample Source Code
Size: 3 KB, Last Update:5 Nov 2001
Sample Source Code
The sample source code is no longer included in the faq. To ge