为什么服务器端给客户端发送带外数据,客户端的OnOutOfBandData触发不了??
有没有人遇到过这个问题?
PS:
1、客户端其它事件如OnConnect,OnReceive,OnSend,OnClose都能正常触发;
2、服务器端的带外数据发送没有问题,确实发出去了;
3、客户端部分主要源码如下:/*
   MyEchoSocket.h
*/
class MyEchoSocket : public CAsyncSocket
{
public:
MyEchoSocket();
virtual ~MyEchoSocket(); void SetParentDlg(CDialog *pDlg); virtual void OnAccept(int nErrorCode);
virtual void OnClose(int nErrorCode);
virtual void OnConnect(int nErrorCode);
virtual void OnOutOfBandData(int nErrorCode);
virtual void OnReceive(int nErrorCode);
virtual void OnSend(int nErrorCode);

private:
CDialog * m_pDlg;
};
/*
   MyEchoSocket.cpp
*/
MyEchoSocket::MyEchoSocket()
{
}MyEchoSocket::~MyEchoSocket()
{
}
void MyEchoSocket::OnAccept(int nErrorCode) 
{
// TODO: Add your specialized code here and/or call the base class
if(nErrorCode==0)
{
((CEchoServerDlg*)m_pDlg)->OnAccept();
}
CAsyncSocket::OnAccept(nErrorCode);
}void MyEchoSocket::OnClose(int nErrorCode) 
{
// TODO: Add your specialized code here and/or call the base class
if(nErrorCode==0)
{
((CEchoServerDlg*)m_pDlg)->OnClose(); 
}
CAsyncSocket::OnClose(nErrorCode);
}void MyEchoSocket::OnConnect(int nErrorCode) 
{
// TODO: Add your specialized code here and/or call the base class CAsyncSocket::OnConnect(nErrorCode);
}//服务器端不停的发带外数据,而该函数却触发不了
void MyEchoSocket::OnOutOfBandData(int nErrorCode) 
{
// TODO: Add your specialized code here and/or call the base class AfxMessageBox("Get it\n");

CAsyncSocket::OnOutOfBandData(nErrorCode);
}void MyEchoSocket::OnReceive(int nErrorCode) 
{
// TODO: Add your specialized code here and/or call the base class
if(nErrorCode==0)
{
   ((CEchoServerDlg*)m_pDlg)->OnReceive(); 
}

CAsyncSocket::OnReceive(nErrorCode);
}void MyEchoSocket::OnSend(int nErrorCode) 
{
// TODO: Add your specialized code here and/or call the base class

CAsyncSocket::OnSend(nErrorCode);
}void MyEchoSocket::SetParentDlg(CDialog *pDlg)
{
   m_pDlg=pDlg;
}

解决方案 »

  1.   

    兄弟,我无语了。PS:
    1、网址、端口都正确,客户端和服务器端确实连接上;
    2、两者互发普通数据,都能触发OnReceive;
    3、两者互发带外数据都触发不了OnOutOfBandData;
    4、为了验证带外数据确实发送出去了,我在LINUX平台下用C语言写了一个服务器端,确实能够收到带外数据。
    5、现在的问题是OnOutOfBandData触发不了,也就收不到带外数据。
      

  2.   

    Send out-of-band data (SOCK_STREAM only).
      这是MSDN里的原话,你用的是TCP连接还是UDP连接,只支持STREAM ,马上我也试一下发送带外数据的