| |
| BOOL Accept( |
| |
SOCKET hServer, |
|
| |
UINT nTimeout, |
|
| |
DWORD dwOptions, |
|
| |
HWND hEventWnd, |
|
| |
UINT uEventMsg |
|
| ); |
| BOOL Accept( |
| |
CSocketWrench&
swServer, |
|
| |
UINT nTimeout, |
|
| |
DWORD dwOptions, |
|
| |
HWND hEventWnd, |
|
| |
UINT uEventMsg |
|
| ); |
The Accept method is used to accept a connection on a
listening socket.
This method is included for backwards compatibility with legacy
applications. New projects should use the CInternetServer
class to to create a server application.
Parameters
- hServer
- Handle to the listening socket. This argument may also
reference a CSocketWrench object which is listening for
connections. In either case, the server socket must have been
created by calling the Listen method.
- nTimeout
- The number of seconds that the server will wait for a client
connection before failing the operation. This value is used only
for blocking connections.
- dwOptions
- An unsigned integer that specifies one or more options. This
parameter is constructed by using a bitwise operator with any of
the following values:
| Constant |
Description |
| 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_REUSEADDRESS |
This option specifies the local address can be reused.
This option is commonly used by server applications. |
| 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_INLINE |
This option controls how urgent (out-of-band) data is
handled when reading data from the socket. If set, urgent data
is placed in the data stream along with non-urgent data. |
| INET_OPTION_TRUSTEDSITE |
This option specifies the server is trusted. The server
certificate will not be validated and the connection will always
be permitted. This option only affects connections using either
the SSL or TLS protocols. |
| INET_OPTION_SECURE |
This option determines if a secure connection is
established with the remote host. |
| INET_OPTION_SECURE_FALLBACK |
This option specifies the server should permit the use
of less secure cipher suites for compatibility with legacy
clients. If this option is specified, the server will allow
connections using TLS 1.0 and cipher suites that use RC4, MD5
and SHA1. |
| INET_OPTION_FREETHREAD |
This option specifies that this instance of the class 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 class instance is synchronized across multiple
threads. |
- hEventWnd
- The handle to the event notification window. This window
receives messages which notify the application of various
asynchronous socket events that occur. If this argument is NULL,
then the connection will be blocking and no network events will be
sent to the client.
- uEventMsg
- The message identifier that is used when an asynchronous socket
event occurs. This value should be greater than WM_USER as defined
in the Windows header files. If the hEventWnd argument is
NULL, this argument should be specified as WM_NULL.
Return Value
If the method succeeds, the return value is non-zero. If the
method fails, the return value is zero. To get extended error
information, call GetLastError.
Remarks
The use of Windows event notification messages has been deprecated
and may be unavailable in future releases. It was designed for use in
legacy single-threaded applications and requires the application to
have a message pump to process event messages. It should not be used
with applications which are designed to execute as a service or those
which do not have a graphical user interface.
To prevent this method from blocking the main user interface thread,
the application should create a background worker thread and establish
a connection by calling Accept in that thread. If
the application requires multiple simultaneous connections, it is
recommended you create a worker thread to accept each client session.
When a connection is accepted by the server, the original
listening socket continues to listen for more connections. If no
event notification window is specified, then Accept will block
until a client attempts to connect to the server or the timeout
period expires.
If you specify an event notification window, then the connection
will be asynchronous. When a message is posted to the notification
window, the low word of the lParam parameter contains the
event identifier. The high word of lParam contains the low
word of the error code, if an error has occurred. The wParam
parameter contains the socket handle. One or more of the following
event identifiers may be sent:
| Constant |
Description |
| INET_EVENT_DISCONNECT |
The remote host has closed the connection. The process should
read any remaining data and disconnect. |
| INET_EVENT_READ |
Data is available to read by the calling process. No
additional messages will be posted until the process has read at
least some of the data from the socket. This event is only
generated if the socket is in asynchronous mode. |
| INET_EVENT_WRITE |
The process can now write data. This notification is sent
after a connection has been established, or after a previous
attempt to write data has failed because it would result in a
blocking operation. This event is only generated if the socket is
in asynchronous mode. |
It is recommended that you only establish an asynchronous
connection if you understand the implications of doing so. In most
cases, it is preferable to create a synchronous connection and create
threads for each additional connection if more than one active
connection is required.
The dwOptions argument can be used to specify the threading
model that is used by the library when a connection is established.
By default, the class instance is initially attached to the thread
that created it. From that point on, until the it is released, only
the owner may call methods using that instance of the class. The
ownership of the class instance may be transferred from one thread to
another using the AttachThread method.
Specifying the INET_OPTION_FREETHREAD option enables any thread to
call any method in that instance of the class, regardless of which
thread created it. It is important to note that this option disables
certain internal safety checks which are performed by the library and
may result in unexpected behavior unless access to the class instance
is synchronized. If one thread calls a function in the library, it
must ensure that no other thread will call another function at the
same time using the same instance.
Requirements
Minimum Desktop Platform: Windows 7 (Service Pack 1)
Minimum Server Platform: Windows Server 2008 R2 (Service Pack 1)
Header: Include cswsock10.h
Import Library: cswskv10.lib
Unicode: Implemented as Unicode and ANSI versions.
See Also
Accept,
Connect, Disconnect,
Listen,
Reject
|
|