|
Creates a socket.
- Parameters
-
family | Address family that the socket will use, defined by the fnet_address_family_t. |
type | Type specification for the new socket, defined by fnet_socket_type_t. It can be SOCK_STREAM (TCP) or SOCK_DGRAM (UDP). |
protocol | Protocol to be used with the socket that is specific to the indicated address family. This stack supports IPPROTO_TCP and IPPROTO_UDP.
This parameter is optional, and can be set to zero, as the type already defines the proper protocol. |
- Returns
- This function returns:
- Socket descriptor referencing the new socket, if no error occurs.
- FNET_NULL if an error occurs.
The specific error code can be retrieved using the fnet_error_get().
- See also
- fnet_socket_close()
This function creates a socket and returns its descriptor.
The fnet_socket() function causes a socket descriptor and any related resources to be allocated and bound to a specific transport-service provider that supports the requested combination of address family, socket type, and protocol parameters.
After a socket is created:
- Connection-oriented sockets, such as the SOCK_STREAM, provide full-duplex connections. Before any data can be sent or received, it must be in a connected state . A connection to another socket is established with the fnet_socket_connect() call. Once connected, the data can be transferred using the fnet_socket_send() and the fnet_socket_recv() calls. When a session has been completed, the fnet_socket_close() must be performed.
- Connectionless, message-oriented sockets, such as the SOCK_DGRAM, allow sending and receiving of datagrams to and from arbitrary peers using the fnet_socket_sendto() and the fnet_socket_recvfrom(). If such a socket is connected to a specific peer, datagrams can be sent to that peer using the fnet_socket_send(), and can be received only from this peer using the fnet_socket_recv().
|