Important: |
---|
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
This function creates a socket.
SOCKET socket ( int af , int type , int protocol );
Parameters
The following are the only two typespecifications supported for Windows Sockets 1.1:
Value | Description |
---|---|
SOCK_STREAM | Provides sequenced, reliable, two-way, connection-based byte streams with an out-of-band data transmission mechanism. Uses TCP for the Internet address family. |
SOCK_DGRAM | Supports datagrams, which are connectionless, unreliable buffers of a fixed (typically small) maximum length. Uses UDP for the Internet address family. |
Return Values
A descriptor referencing the new socket indicates that no error occurred. INVALID_SOCKET indicates failure. To get a specific error value, call WSAGetLastError.
Remarks
For Infrared Sockets (IrSock), this function has the following additional requirements:
The PF_INET and AF_IRDA ARPA Internet address formats are supported.
The socketfunction causes a socket descriptor and any related resources to be allocated and bound to a specific transport service provider. Windows Sockets will utilize the first available service provider that supports the requested combination of address family, socket type and protocol parameters.
Connection-oriented sockets such as SOCK_STREAM provide full-duplex connections, and must be in a connected state before any data can be sent or received on it. A connection to another socket is created with a connectcall. Once connected, data can be transferred using sendand recvcalls. When a session has been completed, a closesocketmust 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 will fail with the error value set to WSAETIMEDOUT.
Connectionless, message-oriented sockets allow sending and receiving of datagrams to and from arbitrary peers using sendtoand recvfrom. If such a socket is connected to a specific peer, datagrams can be sent to that peer using sendand can be received only from this peer using recv.
Requirements
Runs on | Versions | Defined in | Include | Link to |
---|---|---|---|---|
Windows CE OS | 1.0 and later | Winsock.h |
Note This API is part of the complete Windows CE OS package as provided by Microsoft. The functionality of a particular platform is determined by the original equipment manufacturer (OEM) and some devices may not support this API.
See Also
accept, bind, closesocket, connect, getsockname, getsockopt, ioctlsocket, recvfrom, select, send, sendto, setsockopt, shutdown, WSAStartup