假设不能够判断的话,我的阻塞模式的服务器就要不断的发送东西或者客户端一直处在没有返回值的Recv里面,程序就失控了。救救我~~

解决方案 »

  1.   

    他自己会产生ON_CLOSE事件,你是用MFC编的还是WINSOCK编的?
      

  2.   

    我使用MFC里面的一个叫做CSocket的类来做的,它默认是阻塞模式的.
      

  3.   

    CAsyncSocket::OnClose
    virtual void OnClose( int nErrorCode );ParametersnErrorCodeThe most recent error on a socket. The following error codes apply to the OnClose member function: 0   The function executed successfully.
    WSAENETDOWN   The Windows Sockets implementation detected that the network subsystem failed.
    WSAECONNRESET   The connection was reset by the remote side.
    WSAECONNABORTED   The connection was aborted due to timeout or other failure. 
    ResCalled by the framework to notify this socket that the connected socket is closed by its process. For more information, see the articleWindows Sockets: Socket Notifications in Visual C++ Programmer's Guide.
      

  4.   

    我没有写成一大堆的类代码。
    我是这样的
    CSocket G02_sockSrvr;
    G02_sockSrvr.Create(Port);
    G02_sockSrvr.Listen();
    这种简单的模式
      

  5.   

    你可以重载 CSocket::OnClose(int nErrorCode)函数virtual void CMySocket::OnClose( int nErrorCode )
    {
         if(nErrorCode != 0) //断开了
         {
          }
    }如果断开了,系统会自动调用
    CMySocket::OnClose( int nErrorCode )函数的
      

  6.   

    我改成了下面的代码,但是是不行的,编译不过CSocket G02_sockSrvr;
    int      Port=1080;int test()
    {
    G02_sockSrvr.Create(Port);
    G02_sockSrvr.Listen();
    AfxMessageBox("ok");
    G02_sockSrvr.close();
    }virtual void CMySocket::OnClose( int nErrorCode )
    {
         if(nErrorCode != 0) //断开了
         {
          AfxMessageBox("ok");
          }
    }
      

  7.   

    编译不过?????????你应该新建类,继承csocket,用自己的类,然后重载::OnClose()啊
      

  8.   

    这样行不行啊?我是在做动态连接库的啊,MFC应用程序我知道可以,但是DLL我怎么做啊?我担心出问题啊
      

  9.   

    你可能用int WSAAsyncSelectt(
                    SOCKET s,HWND hWnd,usigned int wMsg,long lEvent);
      它允许用在特定的事件发生时批定一个用户应用程序的WINDOWS消息,
               如
          WAAsyncSelect(your socket,hWnd,WM_USER+n,FD_READ|FD_CLOSE)
    you try!!!!!
    我是搞定了,