OnConnect碰到FD_Read,程序是自动执行OnSend(表示可以发数据),还是根据FD_Read调用OnReceive()函数内容。
请教各位大侠,
客户端在第一次调用
void socket::onconnect()
{ ...
AsyncSelelct(FD_Read);
...
}
程序是自动执行OnSend,表示可以发数据了,还是根据FD_Read调用OnReceive()函数内容。 socket onconnect onreceive
[解决办法]
没看懂你要问什么。流程就是,你先尝试调用发送,看send返回值,如果发送成功,你可以继续调用发送。如果发送失败,但错误表示异步等待(ewouldblock),则需等onsend,才能再次send
[解决办法]
CAsyncSocket::OnReceive ()
Called by the framework to notify this socket that there is data in the buffer that can be retrieved by calling the Receive member function.
[解决办法]
异步都是请求应答式,你不调用相关动作就不会有相关事件通知。你调用了如果没有事件到来也不会有通知。
[解决办法]
应该是在CSocket.OnSend()中调用CSocket.Send()
跟Recieve的过程是一样的。
// 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);
}