| < Day Day Up > |
|
In this chapter, we take our first look at the details of the BSD Sockets API. This discussion is based on the Linux API, but this implementation follows the standard closely, so it will apply to other implementations as well. We focus on the basic Sockets API primitives first, and then in Chapter 4, Advanced Sockets Functions, we look at the more advanced functions. The Sockets functions that are discussed in this chapter are shown in Table 3.1.
Function | Description |
---|---|
socket | Creates a new socket endpoint |
bind | Binds a local address to the socket |
listen | Permits incoming connections for a server socket |
accept | Accepts a new client connection for a server socket |
connect | Connects to a server from a client socket |
recv | Receives data through a socket |
recvfrom | Receives data through a datagram socket |
send | Sends data through a socket |
sendto | Sends data through a datagram socket |
close | Closes a socket endpoint |
htons | Converts short to network byte order |
ntohs | Converts short to host byte order |
htonl | Converts long to network byte order |
ntohl | Converts long to host byte order |
inet_addr | Converts a dotted-notation string to a 32-bit network address |
inet_ntoa | Converts a 32-bit network address to a dotted-notation string |
inet_aton | Converts a dotted-notation string to a 32-bit network address |
The following subsections illustrate the API calls, and discuss any special characteristics of their application and common problems that are associated in their use.
Note | In this chapter, we demonstrate the calls as they appear in standard Linux distributions (which follows the BSD API). For embedded Sockets API implementations, the calls and include files may differ. |
| < Day Day Up > |
|