| |
| SOCKET WINAPI InetConnect(
|
| |
LPCTSTR lpszHostName, |
|
| |
UINT nPort, |
|
| |
UINT nProtocol, |
|
| |
UINT nTimeout, |
|
| |
DWORD dwOptions, |
|
| |
LPSECURITYCREDENTIALS lpCredentials |
|
| );
|
Parameters
- lpszHostName
- A pointer to the name of the server to connect to; this may be
a fully-qualified domain name or an IP address.
- nPort
- The port number the server is listening on. This value must be
greater than zero.
- nProtocol
- The protocol to be used when establishing the connection. This
may be one of the following values:
| Constant |
Description |
| INET_PROTOCOL_TCP |
Specifies the Transmission Control Protocol. This protocol
provides a reliable, bi-directional byte stream. This is the
default protocol. |
| INET_PROTOCOL_UDP |
Specifies the User Datagram Protocol. This protocol is message
oriented, sending data in discrete packets. Note that UDP is
unreliable in that there is no way for the sender to know that the
receiver has actually received the datagram. |
- nTimeout
- The number of seconds to wait for the connection to complete
before failing the current operation.
- dwOptions
- An unsigned long integer used to specify one or more socket
options. This parameter is constructed by using the bitwise Or
operator with any of the following values:
| Constant |
Description |
| INET_OPTION_BROADCAST |
This option specifies that broadcasting should be enabled for
datagrams. This option is invalid for stream sockets. |
| INET_OPTION_DONTROUTE |
This option specifies default routing should not be used. This
option should not be specified unless absolutely necessary. |
| INET_OPTION_KEEPALIVE |
This option specifies that packets are to be sent to the remote
system when no data is being exchanged to keep the connection
active. This is only valid for stream sockets. |
| INET_OPTION_NODELAY |
This option disables the Nagle algorithm, which buffers
unacknowledged data and insures that a full-size packet can be sent
to the remote host. |
| INET_OPTION_SECURE |
This option specifies that a secure connection should be
established with the remote host. |
| INET_OPTION_FREETHREAD |
This option specifies that the socket returned by this function
may be used by any thread, and is not limited to the thread which
created it. The application is responsible for ensuring that access
to the socket is synchronized across multiple threads. |
- lpCredentials
- A pointer to a SECURITYCREDENTIALS structure. This
parameter is only used if INET_OPTION_SECURE is specified for a TCP
connection. This parameter may be NULL, in which case no client
credentials will be provided to the server. If client credentials
are required, the fields dwSize, lpszCertStore, and
lpszCertName must be defined, while other fields may be left
undefined. Set dwSize to the size of the
SECURITYCREDENTIALS structure.
Return Value
If the function succeeds, the return value is a handle to a
socket. If the function fails, the return value is INVALID_SOCKET.
To get extended error information, call
InetGetLastError.
Remarks
When this function is called with UDP as the specified protocol,
it does not actually establish a connection. Instead, it simply
establishes a default destination IP address and port that is used
with subsequent InetRead and InetWrite calls.
To enable asynchronous event notification, use the
InetEnableEvents function.
Requirements
Client: Requires Windows 7, Windows Vista or Windows
XP.
Server: Requires Windows Server 2008 or Windows Server
2003.
Header: Include cswsock7.h.
Library: Use cswskav7.lib.
Unicode: Implemented as Unicode and ANSI versions.
See Also
InetAsyncConnect, InetAsyncConnectEx, InetConnectEx, InetDisableEvents, InetDisconnect, InetEnableEvents, InetInitialize, InetRead, InetWrite
|
|