Sockets share some common characteristics.
The connection that a socket provides can be connection-oriented or connectionless. Connection-oriented communication implies that a connection is established, and a dialog between the programs follows. The program that provides the service (the server program) establishes the available socket that is enabled to accept incoming connection requests. Optionally, the server can assign a name to the service that it supplies which allows clients to identify where to obtain and how to connect to that service. The client of the service (the client program) must request the service of the server program. The client does this by connecting to the distinct name or to the attributes associated with the distinct name that the server program has designated. It is similar to dialing a telephone number (an identifier) and making a connection with another party that is offering a service (for example, a plumber). When the receiver of the call (the server, in this example, a plumber) answers the telephone, the connection is established. The plumber verifies that you have reached the correct party, and the connection remains active as long as both parties require it.
Connectionless communication implies that no connection is established over which a dialog or data transfer can take place. Instead, the server program designates a name that identifies where to reach it (much like a post office box). If you send a letter to a post office box, you cannot be absolutely sure the receiver got the letter. You might need to wait for a response to your letter. There is no active, real-time connection in which data is exchanged.
When an application creates a socket with the socket() function, it must identify the socket by specifying these parameters:
These parameters or characteristics define the socket application and how it interoperates with other socket applications. Depending on the address family of a socket, you have different choices for the socket type and protocol. The following table shows the corresponding address family and its associated socket type and protocols:
Address family | Socket type | Socket protocol |
---|---|---|
AF_UNIX | SOCK_STREAM | N/A |
SOCK_DGRAM | N/A | |
AF_INET | SOCK_STREAM | TCP |
SOCK_DGRAM | UDP | |
SOCK_RAW | IP, ICMP | |
AF_INET6 | SOCK_STREAM | TCP |
SOCK_DGRAM | UDP | |
SOCK_RAW | IP6, ICMP6 | |
AF_UNIX_CCSID | SOCK_STREAM | N/A |
SOCK_DGRAM | N/A |
In addition to these socket characteristics or parameters, constant values are defined in network routines and header files that are shipped with the QSYSINC library. For descriptions of header files, see the individual APIs. Each API lists its appropriate header file in the usage section of the API description.
Socket network routines allow socket applications to obtain information from the Domain Name System (DNS), host, protocol, service, and network files.