我用CSocket
在接受服务器数据
ps->Receive时,发生错误
他说非法操作
错误代码好像是
WSAEINPROGRESS

解决方案 »

  1.   

    char serverbuf[1024];
    int buflen=pSocket->Receive(serverbuf,1024,0);//出错
      

  2.   

    我估计是你在多个任务(线程)中同时调用了Reveive函数,而window socket编程环境中一个任务只允许单个的阻塞操作(block)。
    你是不是采用了多线程进行开发的?
      

  3.   

    有关pSocket的部分能不能也贴出来?
    声明、赋值的部分
      

  4.   

    WSAEINPROGRESS   A blocking Windows Sockets operation is in progress.
      

  5.   

    //client.h
    class Client : public CSocket
    {
    // Attributes
    public:// Operations
    public:
    Client(CNtDlg* pdlg);
    virtual ~Client();
    CNtDlg* m_dlg;
    virtual void OnConnect(int nErrorCode);
    virtual void OnReceive(int nErrorCode);
    // Overrides
    public:
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(Client)
    public: //}}AFX_VIRTUAL // Generated message map functions
    //{{AFX_MSG(Client)
    // NOTE - the ClassWizard will add and remove member functions here.
    //}}AFX_MSG// Implementation
    protected:
    };//client.cpp#include "NtDlg.h"
    /////////////////////////////////////////////////////////////////////////////
    // ClientClient::Client(CNtDlg* pdlg)
    {
    m_dlg=pdlg;
    }Client::~Client()
    {
    }
    // Do not edit the following lines, which are needed by ClassWizard.
    #if 0
    BEGIN_MESSAGE_MAP(Client, CAsyncSocket)
    //{{AFX_MSG_MAP(Client)
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    #endif // 0/////////////////////////////////////////////////////////////////////////////
    // Client member functionsvoid Client::OnConnect(int nErrorCode) 
    {
    // TODO: Add your specialized code here and/or call the base class

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

    CSocket::OnReceive(nErrorCode);
    m_dlg->Serverdata();
    }
      

  6.   

    还得把pSocket定义部分也贴出来。
      

  7.   

    Client *pSocket;
    char serverbuf[1024];
    CString m_ip;
    int m_port;
    int Trycount;
    void Serverdata();
      

  8.   

    对不起,还得要看pSocket的申明及其赋值部分的代码。
      

  9.   

    pSocket=new Client(this);
    if (!pSocket->Create())
    {
    int nResult = GetLastError();
    WSASetLastError(nResult);
    delete pSocket;
    pSocket = NULL;
    //AfxMessageBox("套接字创建失败");
    //return 1;
    }
    int nResult = GetLastError();
    WSASetLastError(nResult);
    m_ip="210.51.0.33";
    m_port=5432;
    //MessageBox(m_ip,"ip");
    while(!pSocket->Connect(m_ip,m_port))
    {
    if(Trycount>2)
    {
    delete pSocket;
    pSocket=NULL;
    //MessageBox("连接服务器失败");
    return 1;
    }
    Trycount++;
    }
    char strsendbuf[1234];
    strsend=senddata;
    int ns=pSocket->Send(strsendbuf,fulllen,0);
      

  10.   

    哦,问题可能在那里:
    void Client::OnReceive(int nErrorCode) 
    {
    // TODO: Add your specialized code here and/or call the base class

    CSocket::OnReceive(nErrorCode);
    m_dlg->Serverdata();
    }   m_dlg->Serverdata(); 一行应该放在CSocket::OnReceive(nErrorCode);
    的前面,也就是如下:
    void Client::OnReceive(int nErrorCode) 
    {
    // TODO: Add your specialized code here and/or call the base class

    m_dlg->Serverdata();
    CSocket::OnReceive(nErrorCode);
    }
      

  11.   


    char serverbuf[1024];
    该为
    char serverbuf[1025];
      

  12.   

    去掉这两句!
    int nResult = GetLastError();
    WSASetLastError(nResult);
      

  13.   

    我跟踪进去,发现他在执行
    CAsyncSocket::recv()的时候出错
    而且,lpBuf参数无效