一个古怪的问题,求救高手。

westfish_wu 2003-12-12 01:46:58
我的一个程序的两个拷贝,对连时没有问题,用hub连接也没有问题,一上的大网络上就出错。
错误是这样的:其中一台给另一台发送时没有问题,反过来发时,另一台的OnReceive 函数总是执行两遍,为何?(第二遍当然收不到信息了。)
...全文
44 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
westfish_wu 2003-12-12
  • 打赏
  • 举报
回复
void CClientSocket::OnReceive(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
CString strPath,strName,str;
Message msContent;
memset(&msContent,0,sizeof(msContent));
Receive(&msContent,sizeof(msContent));//接收数据
TCHAR MsgType;
MsgType=msContent.cMsgType;
TRACE("MsgType:%c",MsgType);
if(msContent.cMsgType==_T('m'))
TRACE("信息2\n");
else
TRACE("信息3\n");
CSocket::OnReceive(nErrorCode);

}

收到消息后 运行输出结果如下:
msgtype:m
信息2
msgtype:信息3

我的笔记本电脑没有这个问题,台式机有,好郁闷呀。
westfish_wu 2003-12-12
  • 打赏
  • 举报
回复
代码如上,这个函数这行两次,第一次输出:信息2第二次输出信息3。
再我的笔记本电脑上是执行一次,在台式机上执行两次。为何?
westfish_wu 2003-12-12
  • 打赏
  • 举报
回复
void CClientSocket::OnReceive(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
CMainFrame * pFrame=(CMainFrame *)AfxGetMainWnd();
CString strPath,strName,str;
strPath=theApp.m_strFilePath;
Message msContent;
memset(&msContent,0,sizeof(msContent));
Receive(&msContent,sizeof(msContent));//接收数据
TRACE("msContent :%s\n",msContent.SendDate );
TCHAR MsgType;
MsgType=msContent.cMsgType;
if (MsgType==_T('c'))
{
TRACE("信息1\n");
}
else
{//命令信息的处理

if(msContent.cMsgType==_T('m'))
{ TRACE("信息2\n");

}
else
TRACE("信息3\n");
}

CSocket::OnReceive(nErrorCode);

}
zjg751206 2003-12-12
  • 打赏
  • 举报
回复
是代码的哪儿设置了变量,肯定条件满足就执行了俩遍
xiaohonghong 2003-12-12
  • 打赏
  • 举报
回复
up
cmsbai 2003-12-12
  • 打赏
  • 举报
回复
贴出来看看吧
popyyb 2003-12-12
  • 打赏
  • 举报
回复
up
LuWei103 2003-12-12
  • 打赏
  • 举报
回复
查阅CSDN
stoneyrh 2003-12-12
  • 打赏
  • 举报
回复
if you don't invoke the function receive in the function onreceive,then the framework will never invoke it again.however if you invoke the function in onreceive twice,then the framework will invoke the function twice.so if you want to do that,you should disable the framework to generate another onreceive event again before you invoke any of receive function.
you can use the function asyncselect
you can read more information in the msdn
zhucde 2003-12-12
  • 打赏
  • 举报
回复
这要看看你的具体代码了.

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧