Windows Sockets: Derived from the socket class

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.