socket()

create endpoint for communication 

Function


SYNOPSIS

#include <sys/types.h>

#include <sys/socket.h>

int socket(int af, int type, int protocol);


DESCRIPTION

The socket() system call creates an endpoint for communication and returns a descriptor. The socket has an indicated type, which defines the semantics of communication. Currently, there are five defined types.

The NuTCRACKER Platform socket support is based on WinSock 2.0.

Connection-oriented sockets such as SOCK_STREAM provide full-duplex connections, and must be in a connected state before any data may be sent or received on it. A connection to another socket is created with a connect() call. Once connected, data may be transferred using send() and recv() calls. When a session has been completed, a close() must be performed.

The communications protocols used to implement a reliable, connection-oriented socket, ensure that data is not lost or duplicated. If data for which the peer protocol has buffer space cannot be successfully transmitted within a reasonable length of time, the connection is considered broken and subsequent calls fail with the error code set to ETIMEDOUT.

Connectionless, message-oriented sockets allow sending and receiving of datagrams to and from arbitrary peers using sendto() and recvfrom(). If such a socket is connect()ed to a specific peer, datagrams may be send to that peer using send() and may be received from (only) this peer using recv().


PARAMETERS

af 

Specifies the address family to be used with the socket. All the address families supported by WinSock 2.0 are supported in the NuTCRACKER Platform. Choices include AF_INET, AF_UNIX, AF_IPX, and so on. Platforms which have support for IPV6 installed may use AF_INET6 for the address family.

type 

Specifies the socket type which defines the semantics of communication.

protocol 

Specifies the appropriate protocol for the address family and socket type. It is indicated by a well known constant specific to each address family. The default protocol (protocol parameter to the socket() call is 0) should be correct for most situations.


RETURN VALUES

If successful, socket() returns a descriptor that references the socket. If an error occurs, it returns a value of -1 and sets errno to one of the following values:

EAFNOSUPPORT 

The specified address family is not supported.

EMFILE 

No more socket descriptors can be created.

ENETDOWN 

The network subsystem has failed.

ENOBUFS 

No buffer space is available. The socket cannot be created.

EPROTONOSUPPORT 

The specified protocol is not supported.

EPROTOTYPE 

The socket type is not supported by the protocol.

ESOCKTNOSUPPORT 

The specified socket type is not supported in this address family.


CONFORMANCE

UNIX 98, with exceptions.


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

The NuTCRACKER Platform supports all the address families that WinSock 2.0 supports.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
accept(), bind(), connect(), getsockname(), getsockopt(), listen(), recv(), select(), send(), shutdown(), socketpair()


PTC MKS Toolkit 10.1 patch 1 Documentation Build 2.