This article describes some functions that can be obtained by deriving your own class from the socket class.
You can derive your own socket class from CAsyncSocket or CSocket to add your own functions. Specifically, these classes provide a large number of virtual member functions that can be rewritten, including OnReceive, OnSend, OnAccept, OnConnect, and OnClose. You can override the functions in the derived socket class and use the notifications they provide when a network event occurs. The Framework calls these notification callback functions to notify you of important socket events, such as receiving data that can start reading. For more information about notification functions, see Windows Sockets: Socket notification. For instructions on rewriting the notification function, see the example application CHATTER and CHATSRVR.
In addition,CSocketClass provides OnMessagePending member functions (an advanced rewrite function ). When a socket extracts messages based on Windows, MFC calls this function. Rewrite allowedOnMessagePendingTo find specific messages from Windows and respond to these messages.
CSocketClassOnMessagePendingCheck the default version when the blocking call is completed.WM_PAINTThe message queue of a message. It schedules and draws messages to improve the display quality. In addition to some useful operations, this also shows a way to rewrite this function by yourself. As another example, you can consider usingOnMessagePendingExecute the following tasks. Assume that you are waiting for the completion of the network transaction to display a dialog box without mode. This dialog box contains a "cancel" button, which can be used to cancel long-time blocking transactions. Rewrite
OnMessagePending
Messages related to the mode-free dialog box may be extracted.
In
OnMessagePending
RewritingTRUEOr the return value of the call is returnedOnMessagePending. This base class version is called if this base class version is used to execute the work you still want.
For more information, see:
- Windows Sockets: Use a socket with an archive
- Windows Sockets: CAsyncSocket class
- Windows Sockets: Blocking
- Windows Sockets: byte sorting
- Windows Sockets: Convert strings