Sockets are classified according to communication properties. Processes usually communicate between sockets of the same type. However, if the underlying communication protocols support the communication, sockets of different types can communicate.
Each socket has an associated type, which describes the semantics of communications using that socket. The socket type determines the socket communication properties such as reliability, ordering, and prevention of duplication of messages. The basic set of socket types is defined in the <SYS\SOCKET.H> file:
/*Standard socket types */ #define SOCK_STREAM 1 /*virtual circuit*/ #define SOCK_DGRAM 2 /*datagram*/ #define SOCK_RAW 3 /*raw socket*/ #define SOCK_SEQPACKET 5 /*sequenced packet stream*/
Other socket types can be defined.
OS/2 supports the basic set of sockets:
SOCK_DGRAM
A datagram socket supports the bidirectional flow of data which is not sequenced, reliable, or unduplicated. A process receiving messages on a datagram socket may find messages duplicated or in an order different from the order sent. Record boundaries in data are, however, preserved. Datagram sockets closely model the facilities found in many contemporary packet-switched networks.
An application can use the sendto() and recvfrom() calls or the sendmsg() and recvmsg() calls to exchange data over a datagram socket. If an application is using datagram sockets and calls connect() fully specifying the destination address, the socket will be considered connected. The application program can then use the other data transfer calls send() and recv() or writev() and readv(). The connected or unconnected method of data transfer stays in effect until connect() is called again with a different destination address.
Datagram sockets may be used to send broadcast messages over TCP/IP and NetBIOS. For TCP/IP, the constant INADDR_BROADCAST, defined in <NETINET\IN.H>, can be used to send a broadcast datagram. For NetBIOS, the address format has a type field that specifies whether the address is unique, multicast, or broadcast.
There is no guarantee for a one-to-one correspondence of send and receive calls. It is possible for data sent by one send() call to be received by more than one different receive call, or the other way around.
Stream sockets are either active or passive. Active sockets are used by clients who actively initiate connection requests with connect(). Passive sockets are used by servers to passively wait for and accept connection requests with the listen() and accept() calls. A passive socket that has indicated its willingness to accept connections with the listen() call cannot be used to initiate connection requests.
After a connection has been established between stream sockets, any of the data transfer calls can be used:
Raw sockets are normally datagram-oriented, though their exact characteristics are dependent upon the interface provided by the protocol. However, raw sockets can be connected if connect() is called to specify the destination address.
After a connection has been established between sequenced packet sockets, any of the data transfer calls can be used:
Topics