Creates an endpoint for communication.
int socket( int af, int type, int protocol );
af
Value | Format |
---|---|
AF_INET |
Internet addresses |
type
Value | Meaning |
---|---|
SOCK_STREAM |
The socket will be used for connections. |
SOCK_DGRAM |
The socket will be used for datagrams.. |
protocol
Literal | Value | Meaning |
---|---|---|
IPPROTO_TCP |
6 | Transmission control protocol |
IPPROTO_UDP |
17 | User datagram protocol |
Sockets of type SOCK_STREAM are sequenced, reliable, two-way connection-based byte streams. A socket must be in a connected state before any data may be sent or received on it. A connection to another socket is created with connect. Once connected, data may be transferred using some variant of send and recv. When a session is complete, you must call shutdown.
The communications protocols used to implement a SOCK_STREAM ensure that data is not lost or duplicated. If a piece of data for which the peer protocol has buffer space cannot be successfully transmitted within a reasonable length of time, the connection is considered broken. Such calls indicate an error with -1 returns. The protocols optionally keep sockets viable by forcing transmissions approximately every minute, in the absence of other activity. An error is then indicated if no response can be elicited on an otherwise idle connection for an extended period (for example, five minutes).
SOCK_DGRAM sockets allow you to send and receive datagrams.
All sockets are, by default, SO_LINGER. If the socket promises reliable delivery of data, the system will block the process on a shutdown attempt until it is able to transmit the data or until it decides it is unable to deliver the information.
-1
and the function sets errno to one of these values:
EBADF |
Invalid file descriptor or file not opened for writing. |
ENOSPC |
No space left on device. |
Versions | Defined in | Include | Link to |
---|---|---|---|
INtime 3.0 | intime/rt/include/sys/socket.h | sys/types.h sys/socket.h |
netiff3m.lib |