6.7 Using Socket Types
A socket type represents the type of communication channel for which a socket serves as an endpoint.
The Networking package sets defaults for these types, so you might not need to read this section.
6.7.1 Understanding Socket Types
A socket’s type has three components:
Family A socket family indicates which protocol and address family is used with this socket. The family may be represented with either an integer constant or a string. A sample family and the associated integer and string identifiers are shown below.
Family | Integer identifier | String identifier |
Internet | AF_INET | “inet” |
The only family fully implemented in the Networking package is the Internet protocol family. However, you can add your own address families.
Type The communication semantics of the channel are indicated through an integer type, as shown below. The Networking package does not support all types.
Type | Integer identifier | String identifier |
Datagram socket | SOCK_DGRAM | “dgram” |
Stream socket | SOCK_STREAM | “stream” |
Protocol
The protocol specifies a specific protocol to be used by the channel. Generally only experts need this feature. The protocol indicated by the family and type of the socket is all that is necessary. The specific values allowed for the protocol vary.
6.7.2 Representing a Socket Type
In the Networking package, a socket address type is represented by an
RWSockType object. This is a concrete class that does not have virtual functions, but does have copying and assignment semantics. The
RWInetType class can be used to construct an
RWSockType for the Internet family of classes. Because
RWSockType is a concrete class, these derived classes can be converted to instances of
RWSockType with no change in the semantics of the object.