Next: Servers
Up: Sockets
Previous: Socket Concepts
- These are the system calls involving sockets:
- socket, Creates a socket
- close, Destroys a socket
- connect, Creates a connection between two sockets
- bind, Labels a server socket with an address
- listen, Configures a socket to accept conditions
- accept, Accepts a connection and creates a new socket for the connection
Sockets are represented by file descriptors.
- Creating and Destroying Sockets
- The socket and close functions create and destroy sockets, respectively.
- When you create a socket, specify the three socket choices: namespace, communication style, and protocol.
- PF_LOCAL or PF_UNIX specifies the local namespace,
and PF_INET specifies Internet namespaces.
- SOCK_STREAM for a connection-style socket, or use
SOCK_DGRAM for a datagram-style socket.
- Each protocol is valid for a particular namespace-style combination. Because there is usually one best protocol for each such pair, specifying 0 is usually the correct protocol.
- If socket succeeds, it returns a file descriptor for the socket. You can
read from or write to the socket using read, write, and so on, as with other file descriptors.
- When you are finished with a socket, call close to remove it.
Next: Servers
Up: Sockets
Previous: Socket Concepts
Cem Ozdogan
2007-04-16