怎么判断CAsyncSocket::send是否发送成功? 如题多谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 函数返回!=SOCKET_ERROR 即为函数执行成功,但对方是否收到需要由程序进行其他处理。 看返回值see MSDN Sample:// CMyAsyncSocket is derived from CAsyncSocket and defines the // following variables:// CString m_sendBuffer; //for async send// int m_nBytesSent;// int m_nBytesBufferSize;void CMyAsyncSocket ::OnSend(int nErrorCode){ while (m_nBytesSent < m_nBytesBufferSize) { int dwBytes; if ((dwBytes = Send((LPCTSTR)m_sendBuffer + m_nBytesSent, m_nBytesBufferSize - m_nBytesSent)) == SOCKET_ERROR) { if (GetLastError() == WSAEWOULDBLOCK) break; else { TCHAR szError[256]; wsprintf(szError, "Server Socket failed to send: %d", GetLastError()); Close(); AfxMessageBox (szError); } } else { m_nBytesSent += dwBytes; } } if (m_nBytesSent == m_nBytesBufferSize) { m_nBytesSent = m_nBytesBufferSize = 0; m_sendBuffer = ""; } CAsyncSocket::OnSend(nErrorCode);}if (dwBytes>=0) 就是每次send的字节数if (dwBytes = -1)就有错误(除WSAEWOULDBLOCK 发送缓冲满) 你应该了解一下同步异步Socket的区别。 学习基于分层窗口(layered window),刚做的桌面半透明时钟 [ODBC]SQLConfigDataSource()配置SQL Server时不能填UID和PWD么? 问俩菜问题... 线程通信(postmessage)的问题 数据显示问题 菜鸟求助!!!!! 多文档窗口怎么向子窗口菜单中添加菜单项? 用CreateFile函数怎样判断打印机和绘图仪在并口上是开着并通电的? 如何让程序自动运行?? 有没有方法用HTTP协议从客户端向服务器端上传数据文件? 接口增加引用计数时出错,不明白。 明天去一家基于网络开发的公司面试,请问该注意点什么?
see MSDN Sample:
// CMyAsyncSocket is derived from CAsyncSocket and defines the
// following variables:
// CString m_sendBuffer; //for async send
// int m_nBytesSent;
// int m_nBytesBufferSize;void CMyAsyncSocket ::OnSend(int nErrorCode)
{
while (m_nBytesSent < m_nBytesBufferSize)
{
int dwBytes; if ((dwBytes = Send((LPCTSTR)m_sendBuffer + m_nBytesSent,
m_nBytesBufferSize - m_nBytesSent)) == SOCKET_ERROR)
{
if (GetLastError() == WSAEWOULDBLOCK) break;
else
{
TCHAR szError[256];
wsprintf(szError, "Server Socket failed to send: %d",
GetLastError());
Close();
AfxMessageBox (szError);
}
}
else
{
m_nBytesSent += dwBytes;
}
}
if (m_nBytesSent == m_nBytesBufferSize)
{
m_nBytesSent = m_nBytesBufferSize = 0;
m_sendBuffer = "";
}
CAsyncSocket::OnSend(nErrorCode);
}
if (dwBytes>=0) 就是每次send的字节数
if (dwBytes = -1)就有错误(除WSAEWOULDBLOCK 发送缓冲满)