MFC网络事件通知

本文介绍了MFC网络编程中的通知函数,包括OnReceive、OnSend等,它们用于响应网络事件,如数据接收、发送、连接请求等。通过AsyncSelect函数可以指定哪些回调通知函数会被调用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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为非阻塞模式。参数为上述网络事件通知,可以组合~~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值