寻找实现MFC的casyncsocket的示例代码 [英] Looking for sample code that implements MFC's casyncsocket

查看:83
本文介绍了寻找实现MFC的casyncsocket的示例代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能指出实际使用CAsyncSocket的示例代码,其中服务器的OnAccept通知分离套接字,重新将其附加到另一个线程中吗?



目前,我的prototype必须销毁监听器套接字并重新创建它,以便它能够从客户端获得MyServerCAsyncSocket :: OnAccept第二个MyClientCAsyncSocket :: Connect-ion。这不应该是它的工作方式。监听器套接字应该保持打开状态,等待来自客户端的下一个数据。



但似乎没有任何可用的示例代码,我可以从中确定我在代码中做错了什么。因此,我的要求。



我的尝试:



我尝试过Detach and Attach。在Detach之后,我设置了MSDN规定的m_hSocket = NULL,但是做了一个ASSERT(m_hSocket == INVALID_SOCKET),它是-1,而不是NULL。

Can someone point me to sample code that actually uses CAsyncSocket where the server's OnAccept notification Detaches the socket, re-Attaches it in another thread?

Currently, my prototype has to destroy the listener socket and re-create it in order for it to be able to MyServerCAsyncSocket::OnAccept a second MyClientCAsyncSocket::Connect-ion from the client. That is not supposed to be how it works. The listener socket is supposed to remain open waiting for the next data from the client.

But there doesn't seem to be any working sample code from which I could determine what I am doing wrong in my code. Hence, my request.

What I have tried:

I have tried Detach and Attach. After Detach, I set the m_hSocket = NULL which MSDN prescribes, but does an ASSERT( m_hSocket == INVALID_SOCKET ) which is -1, not NULL.

推荐答案

为简单起见我会一直使用一个新的插座。



正如ASSERT所说:set

For simplicity I would use always a new socket.

As the ASSERT tells: set
m_hSocket = INVALID_SOCKET;



完成后。如果您使用某些第三方代码=>遵守其规则。



查看此示例项目


Visual Studio C ++论坛中的Igor Tandetnik向示例程序指出了一张海报,其中显示了一个功能齐全的CAsyncSocket。该程序MFCSOCS.EXE可以从http://ftplike.com下载ftp(搜索MFCSOCS.EXE)。这是唯一一个在一个简单的客户端/服务器程序中显示CAsyncSocket如何工作的示例程序,它实际上隐式显示其通知的真实状态图(OnReceive,OnConnect,OnSend,OnOutOfBandData和OnClose)及其动词(Receive,Connect,Accept) ,发送和关闭)。我认为,这些关系无法从MSDN的参考资料中推断出来。当然,除非您已经知道MS在一开始就建议的关系是什么。
Igor Tandetnik in the Visual Studio C++ forum pointed a poster to a sample program and that showed a fully functioning CAsyncSocket. This program, MFCSOCS.EXE, may be ftp downloaded from http://ftplike.com (search for MFCSOCS.EXE). This is the only sample program that showed in one easy client/server program how CAsyncSocket works which in effect implicitly shows the true state diagram of its notifications (OnReceive, OnConnect, OnSend, OnOutOfBandData and OnClose) and their verbs (Receive, Connect, Accept, Send and Close). These relationships, I contend, cannot be deduced from MSDN's reference material. Unless, of course, you already know what the relationships are which is what MS advises at the outset.


这篇关于寻找实现MFC的casyncsocket的示例代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆