socket

This function creates a socket.

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

Parameters

  • af
    [in] Address family specification.

  • type
    [in] Type specification for the new socket.

    The following are the only two type specifications 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.
  • protocol
    [in] Particular protocol to be used with the socket that is specific to the indicated 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:

  • Af_irda.h must be explicitly included.
  • Set the af parameter to AF_IRDA, and set the protocol parameter to NULL.

The PF_INET and AF_IRDA ARPA Internet address formats are supported.

The socket function 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 connect call. Once connected, data can be transferred using send and recv calls. When a session has been completed, a closesocket 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 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 sendto and recvfrom. If such a socket is connected to a specific peer, datagrams can be sent to that peer using send and 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

 Last updated on Tuesday, July 13, 2004

© 1992-2000 Microsoft Corporation. All rights reserved.