在CServer::OnReceive中的错误???在线等急 急 急谢谢

scaleyuming 2005-08-18 11:51:07
void CServer::OnReceive(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
char buff[10];
int bufflen=10;

CString ClientName;
int nLen = Receive(buff,bufflen);//接收
ClientName.Format(inet_ntoa(ClientAddr.sin_addr));//返回客户端的ip地址
if(buff[0]=='F')
{
CString str;
str="ok";

int len=str.GetLength();
m_pSock->Send(str,2,0);//就在这出的 问题????


}
CSocket::OnReceive(nErrorCode);
}
void CServer::OnAccept(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
CServer* pSocket=new CServer;
int iLen=sizeof(ClientAddr);
Accept(*pSocket,(LPSOCKADDR)&ClientAddr,&iLen);
m_pSock=pSocket;//不知道这样赋值对部队,我觉的这个地方有问题m_pSock是CServer的对象

//CSocket::OnAccept(nErrorCode);
}
/////CServer是由CSocket派生的

当程序执行到CServer::OnReceive里面的m_pSock->Send(str,2,0);
就出现错误:
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts

(Press Retry to debug the application)

终止(A) 重试(R) 忽略(I)

如果我把m_pSock->Send(str,2,0);放在void CServer::OnAccept里发送就没问题 ,不知道为啥,本人是个入门级的 呵呵 谢谢


...全文
98 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
nuaawenlin 2005-08-19
  • 打赏
  • 举报
回复
Accept(*pSocket,(LPSOCKADDR)&ClientAddr,&iLen);

变为

Accept((CSocket *)m_pSocket,(LPSOCKADDR)&ClientAddr,&iLen);
i_noname 2005-08-18
  • 打赏
  • 举报
回复
m_pSock->Send(str,2,0);
"ok"的长度为3!"ok\0".

m_pSock=pSocket;//不知道这样赋值对部队,我觉的这个地方有问题m_pSock是CServer的对象
这个没问题。

18,363

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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