UNIX Socket FAQ

UNIX Socket FAQ

  • About this FAQ

    About this FAQ This FAQ is maintained by Vic Metcalfe ( vic@acm.org ), with lots o

  • Who is this FAQ for?

    Who is this FAQ for? This FAQ is for C programmers in the Unix environment. It is

  • What are Sockets?

    What are Sockets? Sockets are just like "worm holes" in science fiction. When thi

  • How do Sockets Work?

    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]?

    Where can I get source code for the book [book title]? Here is a list of the place

  • Where can I get more information?

    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?

    How can I tell when a socket is closed on the other end? From Andrew Gierth ( andr

  • Why do I get EPROTO from read()?

    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?

    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?

    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?

    How come select says there is data, but read returns zero? The data that causes se

  • Whats the difference between select() and poll()?

    Whats the difference between select() and poll()? From Richard Stevens ( rstevens@

  • How do I send [this] over a socket?

    How do I send [this] over a socket? Anything other than single bytes of data will

  • How do I use TCP_NODELAY?

    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?

    What exactly does the Nagle algorithm do? It groups together as much data as it ca

  • What is the difference between read() and recv()?

    What is the difference between read() and recv()? From Andrew Gierth ( andrew@erle

  • I see that send()/write() can generate SIGPIPE

    I see that send()/write() can generate SIGPIPE checking for the EPIPE error? Are there an

  • What's with the second parameter in bind()?

    What's with the second parameter in bind()? The man page shows it as "struct socka

  • After the chroot(), calls to socket() are failing

    After the chroot(), calls to socket() are failing From Andrew Gierth ( andrew@erlenstar.d

  • Why do I keep getting EINTR from the socket calls?

    Why do I keep getting EINTR from the socket calls? This isn't really so much an er

  • When will my application receive SIGPIPE?

    When will my application receive SIGPIPE? From Richard Stevens ( rstevens@noao.edu

  • What are socket exceptions? What is out-of-band data?

    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

    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?

    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?

    If bind() fails, what should I do with the socket descriptor? If you are exiting,

  • How do I properly close a socket?

    How do I properly close a socket? This question is usually asked by people who try

  • When should I use shutdown()?

    When should I use shutdown()? From Michael Hunter ( mphunter@qnx.com ): shutd

  • Please explain the TIME_WAIT state.

    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?

    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?

    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?

    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?

    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

    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

    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?

    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()

    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?

    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 ?

    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()?

    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?

    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?

    What is the difference between SO_REUSEADDR and SO_REUSEPORT? SO_REUSEADDR allows

  • How can I write a multi-homed server?

    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?

    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

    I'm trying to exec() a program from my server, and attach my If the program you

  • Why don't my sockets close?

    Why don't my sockets close? When you issue the close() system call, you are closin

  • How can I make my server a daemon?

    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?

    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?

    What exactly does SO_REUSEADDR do? This socket option tells the kernel that even i

  • What exactly does SO_LINGER do?

    What exactly does SO_LINGER do? On some unixes this does nothing. On others, it i

  • What exactly does SO_KEEPALIVE do?

    What exactly does SO_KEEPALIVE do? From Andrew Gierth ( andrew@erlenstar.demon.co.

  • How can I bind() to a port number < 1024?

    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-

    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?

    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"

    What is the difference between "connected" and "unconnected" From Andrew Gierth

  • of the socket? Does doing a connect() call affect the receive

    of the socket? Does doing a connect() call affect the receive From Richard Stev

  • How can I read ICMP errors from "connected" UDP sockets?

    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?

    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?

    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?

    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?

    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?

    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?

    How would I put my socket in non-blocking mode? From Andrew Gierth ( andrew@erlens

  • How can I put a timeout on connect()?

    How can I put a timeout on connect()? Andrew Gierth ( andrew@erlenstar.demon.co.uk

  • Sample Source Code

    Sample Source Code The sample source code is no longer included in the faq. To ge



    Home
    FAQ