char sBuf[256];
CString strMsg;
CSocket Pop3;
Pop3.Create();
if( !Pop3.Connect("pop3.sina.com.cn", 110) )
{
AfxMessageBox("连接失败!");
goto LabelExit;
}
strMsg = "USER Abcdefg\r\n";
Pop3.Send( strMsg, strMsg.GetLength() );//这里设断点
Pop3.Receive( sBuf, 256);
if( !strnicmp(sBuf, "-ERR", 4) )
{
AfxMessageBox("密码出错!");
goto LabelExit;
} strMsg = "PASS 87654321\r\n";
Pop3.Send( strMsg, strMsg.GetLength() );
Pop3.Receive( sBuf, 256);//错在这里,即使密码乱写,sBuf也接收不到"-ERR",
//但若用F5从“这里设断点”处一步步的运行就正确。
if( !strnicmp(sBuf, "-ERR", 4) )
{
AfxMessageBox("密码出错!");
goto LabelExit;
}
LabelExit:
strMsg = "QUIT \r\n";//离开
Pop3.Send( strMsg, strMsg.GetLength() );
Pop3.Close();当执行时,即时密码填什么字符都接收不到“-ERR”,但若在F5单步执行下却能接收到“-ERR”。我怀疑是Send和Receive的时间问题。
请指出错误,谢谢!
CString strMsg;
CSocket Pop3;
Pop3.Create();
if( !Pop3.Connect("pop3.sina.com.cn", 110) )
{
AfxMessageBox("连接失败!");
goto LabelExit;
}
strMsg = "USER Abcdefg\r\n";
Pop3.Send( strMsg, strMsg.GetLength() );//这里设断点
Pop3.Receive( sBuf, 256);
if( !strnicmp(sBuf, "-ERR", 4) )
{
AfxMessageBox("密码出错!");
goto LabelExit;
} strMsg = "PASS 87654321\r\n";
Pop3.Send( strMsg, strMsg.GetLength() );
Pop3.Receive( sBuf, 256);//错在这里,即使密码乱写,sBuf也接收不到"-ERR",
//但若用F5从“这里设断点”处一步步的运行就正确。
if( !strnicmp(sBuf, "-ERR", 4) )
{
AfxMessageBox("密码出错!");
goto LabelExit;
}
LabelExit:
strMsg = "QUIT \r\n";//离开
Pop3.Send( strMsg, strMsg.GetLength() );
Pop3.Close();当执行时,即时密码填什么字符都接收不到“-ERR”,但若在F5单步执行下却能接收到“-ERR”。我怀疑是Send和Receive的时间问题。
请指出错误,谢谢!
好像先是"HELO"的字符,然后还有一些东西.......
大家有没有可以运行的POP3例子呢。
今天在
每个Send和Receive之间加插
Sleep(3000);
就没事。
DWORD uArgument = 0;
Pop3.AsyncSelect(0);
Pop3.IOCtl(FIONBIO, &uArgument);//设为阻塞方式
至于加上Sleep(3000),可能是POP3服务器防黑功能吧。
Pop3.AsyncSelect(0);
Pop3.IOCtl(FIONBIO, &uArgument);//设为阻塞方式设为阴塞方式后问题依然存在,非得 Sleep 个三五秒够才行:(