|
WSASocket
The Windows Sockets WSASocket function creates a socket which is bound to a specific transport service
provider, and optionally creates and/or joins a socket group.
SOCKET WSASocket (
int af,
|
| int type,
|
| int protocol,
|
| LPWSAPROTOCOL_INFO lpProtocolInfo,
|
| GROUP g,
|
| DWORD dwFlags
|
| );
|
|
Parameters
af
[in] An address family specification.
type
[in] A type specification for the new socket.
protocol
[in] A particular protocol to be used with the socket which is specific to the
indicated address family.
lpProtocolInfo
[in] A pointer to a WSAPROTOCOL_INFO structure that defines the
characteristics of the socket to be created.
g
[in] The identifier of the socket group.
dwFlags
[in] The socket attribute specification.
Remarks
This function causes a socket descriptor and any related resources to be
allocated and associated with a transport service provider. By default, the socket
will not have an overlapped attribute. If lpProtocolInfo is NULL, the Windows Sockets 2 DLL uses the first three parameters (af, type, protocol) to determine which service provider is used by selecting the first transport
provider able to support the stipulated address family, socket type and
protocol values. If the lpProtocolInfo is not NULL, the socket will be bound to the provider associated with the
indicated WSAPROTOCOL_INFO structure. In this instance, the application may supply
the manifest constant FROM_PROTOCOL_INFO as the value for any of af, type or protocol. This indicates that the corresponding values from the indicated
WSAPROTOCOL_INFO structure (iAddressFamily, iSocketType, iProtocol) are to be assumed. In
any case, the values supplied for af, type and protocol are supplied unmodified to the transport service provider through the
corresponding parameters to the WSPSocket function in the SPI.
Note The manifest constant AF_UNSPEC continues to be defined in the header file
but its use is strongly discouraged, as this may cause ambiguity in interpreting the value of the protocol parameter.
Parameter g is used to indicate the appropriate actions on socket groups:
- if g is an existing socket group ID, join the new socket to this group, provided
all the requirements set by this group are met; or
- if g = SG_UNCONSTRAINED_GROUP, create an unconstrained socket group and have the new socket be the first member; or
- if g = SG_CONSTRAINED_GROUP, create a constrained socket group and have the new
socket be the first member; or
- if g = zero, no group operation is performed
For unconstrained groups, any set of sockets may be grouped together as long
as they are supported by a single service provider. A constrained socket group
may consist only of connection-oriented sockets, and requires that connections
on all grouped sockets be to the same address on the same host. For newly
created socket groups, the new group ID can be retrieved by using getsockopt with option SO_GROUP_ID, if this operation completes successfully. A socket
group and its associated ID remain valid until the last socket belonging to this
socket group is closed. Socket group IDs are unique across all processes for a
given service provider.
The dwFlags parameter may be used to specify the attributes of the socket by or-ing any
of the following Flags:
Flag
| Meaning
| WSA_FLAG_OVERLAPPED
| This flag causes an overlapped socket to be created. Overlapped sockets may
utilize WSASend, WSASendTo, WSARecv, WSARecvFrom and WSAIoctl for overlapped I/O operations, which allows multiple these operations to be
initiated and in progress simultaneously.
| WSA_FLAG_MULTIPOINT_C_ROOT
| Indicates that the socket created will be a c_root in a multipoint session.
Only allowed if a rooted control plane is indicated in the protocol's
WSAPROTOCOL_INFO structure. Refer to Multipoint and Multicast Semantics for additional information.
| WSA_FLAG_MULTIPOINT_C_LEAF
| Indicates that the socket created will be a c_leaf in a multicast session.
Only allowed if XP1_SUPPORT_MULTIPOINT is indicated in the protocol's
WSAPROTOCOL_INFO structure. Refer to Multipoint and Multicast Semantics for additional information.
| WSA_FLAG_MULTIPOINT_D_ROOT
| Indicates that the socket created will be a d_root in a multipoint session.
Only allowed if a rooted data plane is indicated in the protocol's
WSAPROTOCOL_INFO structure. Refer to Multipoint and Multicast Semantics for additional information.
| WSA_FLAG_MULTIPOINT_D_LEAF
| Indicates that the socket created will be a d_leaf in a multipoint session.
Only allowed if XP1_SUPPORT_MULTIPOINT is indicated in the protocol's
WSAPROTOCOL_INFO structure. Refer to Multipoint and Multicast Semantics for additional information.
|
Important For multipoint sockets, exactly one of WSA_FLAG_MULTIPOINT_C_ROOT or
WSA_FLAG_MULTIPOINT_C_LEAF must be specified, and exactly one of WSA_FLAG_MULTIPOINT_D_ROOT or
WSA_FLAG_MULTIPOINT_D_LEAF must be specified. Refer to Multipoint and Multicast Semantics for additional information.
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
them. A connection to another socket is created with a connect/WSAConnect call. Once connected, data may be transferred using send/WSASend and recv/WSARecv 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 code set to WSAETIMEDOUT.
Connectionless, message-oriented sockets allow sending and receiving of
datagrams to and from arbitrary peers using sendto/WSASendTo and recvfrom/WSARecvFrom. If such a socket is connected to a specific peer, datagrams may be sent to that peer using send/WSASend and may be received from (only) this peer using recv/WSARecv.
Support for sockets with type RAW is not required, but service providers are
encourages to support raw sockets whenever it makes sense to do so.
Shared Sockets
When a special WSAPROTOCOL_INFO structure (obtained through the WSADuplicateSocket function and used to create additional descriptors for a shared socket) is
passed as an input parameter to WSASocket, the g and dwFlags parameters are ignored.
Return Values
If no error occurs, WSASocket returns a descriptor referencing the new socket. Otherwise, a value of
INVALID_SOCKET is returned, and a specific error code may be retrieved by calling WSAGetLastError.
Error Codes
WSANOTINITIALISED
| A successful WSAStartup must occur before using this function.
| WSAENETDOWN
| The network subsystem has failed.
| WSAEAFNOSUPPORT
| The specified address family is not supported.
| WSAEINPROGRESS
| A blocking Windows Sockets 1.1 call is in progress, or the service provider is
still processing a callback function.
| WSAEMFILE
| No more socket descriptors are available.
| WSAENOBUFS
| No buffer space is available. The socket cannot be created.
| WSAEPROTONOSUPPORT
| The specified protocol is not supported.
| WSAEPROTOTYPE
| The specified protocol is the wrong type for this socket.
| WSAESOCKTNOSUPPORT
| The specified socket type is not supported in this address family.
| WSAEINVAL
| The parameter g specified is not valid.
|
See Also
accept, bind, connect, getsockname, getsockopt, ioctlsocket, listen, recv, recvfrom, select, send, sendto, setsockopt, shutdown
| Last news from Greatis Software |
 |
|
Nostalgia .Net |
|
.Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes. More » |
| Recommended software for developers |
 |
|
Ultimate Pack |
|
Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price. More » |
 |
|
Form Designer .Net |
|
Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime with full source codes for only 300 euro! More » |
 |
|
Print Suite .Net |
|
Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available More » |
 |
|
Gradient Controls .Net |
|
Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available More » |
 |
|
Greatis iGrid |
|
iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors. More » |
All the contacts and projectsDmitry Vasiliev (just.dmitry)
Related LinksSoftware for Visual Studio .NET developers Software for Delphi and C++ Builder developers Software for Visual Basic 6 developers Delphi Tips&Tricks MegaDetailed.NET More Online Helps Win32 Programmer's Reference Win32 Multimedia Programmer's Reference OLE Programmer's Reference Microsoft Windows Pen API Programmer's Reference Microsoft Windows Sockets 2 Reference Microsoft Windows Telephony API (TAPI) Programmer's Reference Unix Manual Pages
|