MFC网络编程中的网络事件通知
摘自MSDN:
This article describes the notification functions in the socket classes. These member functions are callback functions that the framework calls to notify your socket object of important events. The notification functions are:
-
OnReceive: Notifies this socket that there is data in the buffer for it to retrieve by calling Receive.
-
OnSend: Notifies this socket that it can now send data by calling Send.
-
OnAccept: Notifies this listening socket that it can accept pending connection requests by calling Accept.
-
OnConnect: Notifies this connecting socket that its connection attempt completed: perhaps successfully or perhaps in error.
-
OnClose: Notifies this socket that the socket it is connected to has closed.
以上是通知函数,当相应网络事件发生时,MFC框架自动调用上述函数。
相应的网络事件:
-
FD_READ Want to receive notification of readiness for reading.
-
FD_WRITE Want to receive notification when data is available to be read.
-
FD_ACCEPT Want to receive notification of incoming connections.
-
FD_CONNECT Want to receive notification of connection results.
-
FD_CLOSE Want to receive notification when a socket has been closed by a peer.
如何发起这些通知,让MFC自动调用呢?
使用AsyncSelect()函数:This function is used to specify which MFC callback notification functions will be called for the socket. AsyncSelect automatically sets this socket to nonblocking mode.
这个函数设置socket为非阻塞模式。参数为上述网络事件通知,可以组合~~