CAsyncSocket Class
Represents a Windows Socket — an endpoint of network communication.
class CAsyncSocket : public CObject
Members
Public Constructors
Name |
Description |
---|---|
Constructs a CAsyncSocket object. |
Public Methods
Name |
Description |
---|---|
Accepts a connection on the socket. |
|
Requests event notification for the socket. |
|
Attaches a socket handle to a CAsyncSocket object. |
|
Associates a local address with the socket. |
|
Closes the socket. |
|
Establishes a connection to a peer socket. |
|
Creates a socket. |
|
Detaches a socket handle from a CAsyncSocket object. |
|
Returns a pointer to a CAsyncSocket object, given a socket handle. |
|
Gets the error status for the last operation that failed. |
|
Gets the address of the peer socket to which the socket is connected. |
|
Gets the address of the peer socket to which the socket is connected (handles IPv6 addresses). |
|
Gets the local name for a socket. |
|
Gets the local name for a socket (handles IPv6 addresses). |
|
Retrieves a socket option. |
|
Controls the mode of the socket. |
|
Establishes a socket to listen for incoming connection requests. |
|
Receives data from the socket. |
|
Receives a datagram and stores the source address. |
|
Receives a datagram and stores the source address (handles IPv6 addresses). |
|
Sends data to a connected socket. |
|
Sends data to a specific destination. |
|
Sends data to a specific destination (handles IPv6 addresses). |
|
Sets a socket option. |
|
Disables Send and/or Receive calls on the socket. |
|
Allocates a socket handle. |
Protected Methods
Name |
Description |
---|---|
Notifies a listening socket that it can accept pending connection requests by calling Accept. |
|
Notifies a socket that the socket connected to it has closed. |
|
Notifies a connecting socket that the connection attempt is complete, whether successfully or in error. |
|
Notifies a receiving socket that there is out-of-band data to be read on the socket, usually an urgent message. |
|
Notifies a listening socket that there is data to be retrieved by calling Receive. |
|
Notifies a socket that it can send data by calling Send. |
Public Operators
Name |
Description |
---|---|
Assigns a new value to a CAsyncSocket object. |
|
Use this operator to retrieve the SOCKET handle of the CAsyncSocket object. |
Public Data Members
Name |
Description |
---|---|
Indicates the SOCKET handle attached to this CAsyncSocket object. |
Remarks
Class CAsyncSocket encapsulates the Windows Socket Functions API, providing an object-oriented abstraction for programmers who want to use Windows Sockets in conjunction with MFC.
This class is based on the assumption that you understand network communications. You are responsible for handling blocking, byte-order differences, and conversions between Unicode and multibyte character set (MBCS) strings. If you want a more convenient interface that manages these issues for you, see class CSocket.
To use a CAsyncSocket object, call its constructor, then call the Create function to create the underlying socket handle (type SOCKET), except on accepted sockets. For a server socket call the Listen member function, and for a client socket call the Connect member function. The server socket should call the Accept function upon receiving a connection request. Use the remaining CAsyncSocket functions to carry out communications between sockets. Upon completion, destroy the CAsyncSocket object if it was created on the heap; the destructor automatically calls the Close function. The SOCKET data type is described in the article Windows Sockets: Background.
Note
When using MFC sockets in secondary threads in a statically linked MFC application, you must call AfxSocketInit in each thread that uses sockets to initialize the socket libraries. By default, AfxSocketInit is called only in the primary thread.
For more information, see Windows Sockets: Using Class CAsyncSocket and related articles., as well as Windows Sockets 2 API.
Inheritance Hierarchy
CAsyncSocket
Requirements
Header: afxsock.h