Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to get the client's abort message with WSAAsyncSelect ?

How to get the client's abort message with WSAAsyncSelect ?

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminhelptutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wangningyu
    wrote on last edited by
    #1

    Hello ! I use WSAAsyncSelect to do a small ChatSystem in the WLAN Server. (the max client may be has 100-200 online,and the ordinary time is 30-50 online at the same time.) like this:

    SOCKET sock = (SOCKET) wParam;
    if(WSAGETSELECTERROR(lParam)){
    DeleteClient(sock);
    return;
    }

    switch(WSAGETSELECTEVENT(lParam)){
    case FD_ACCEPT:
    sClient = accept(wParam, (struct sockaddr *)&client, &iAddrSize);
    // Add to the CPtrList
    // ......
    WSAAsyncSelect(sClient, hwnd, WM_SOCKET, FD_READ | FD_CLOSE);
    break;

    case FD_READ:
    ReadData(sock); // Paser the data.
    break;

    case FD_CLOSE:
    DeleteClient(sock); //Del from the CPtrList.
    break;

    default:
    break;
    }

    at last ,when add/del client, it will refresh onlines info to the Server's list control. May be it doesn't receive the FD_CLOSE message. but usually ,it has some few days ago results. I run in the Lan and use other Lan computer to test it, but can't found this problem. How about this ? Thanks for you reply !

    U I 2 Replies Last reply
    0
    • W wangningyu

      Hello ! I use WSAAsyncSelect to do a small ChatSystem in the WLAN Server. (the max client may be has 100-200 online,and the ordinary time is 30-50 online at the same time.) like this:

      SOCKET sock = (SOCKET) wParam;
      if(WSAGETSELECTERROR(lParam)){
      DeleteClient(sock);
      return;
      }

      switch(WSAGETSELECTEVENT(lParam)){
      case FD_ACCEPT:
      sClient = accept(wParam, (struct sockaddr *)&client, &iAddrSize);
      // Add to the CPtrList
      // ......
      WSAAsyncSelect(sClient, hwnd, WM_SOCKET, FD_READ | FD_CLOSE);
      break;

      case FD_READ:
      ReadData(sock); // Paser the data.
      break;

      case FD_CLOSE:
      DeleteClient(sock); //Del from the CPtrList.
      break;

      default:
      break;
      }

      at last ,when add/del client, it will refresh onlines info to the Server's list control. May be it doesn't receive the FD_CLOSE message. but usually ,it has some few days ago results. I run in the Lan and use other Lan computer to test it, but can't found this problem. How about this ? Thanks for you reply !

      U Offline
      U Offline
      User 1312126
      wrote on last edited by
      #2

      hello i hope this will work. don't use WSAAsyncSelect() probably your window might be missing some messages posted by mfc socket framework (This will happen) use WSAEventSelect() by creating one more thread. send notification messages to your main window by using SendMessage() function. it will work perfectly. Possibly one more reason is Socket abort operation notification will take at most 2 msi cylcles ( 1 msi is 2 minutes). this is tcp ip implementation bye yln

      1 Reply Last reply
      0
      • W wangningyu

        Hello ! I use WSAAsyncSelect to do a small ChatSystem in the WLAN Server. (the max client may be has 100-200 online,and the ordinary time is 30-50 online at the same time.) like this:

        SOCKET sock = (SOCKET) wParam;
        if(WSAGETSELECTERROR(lParam)){
        DeleteClient(sock);
        return;
        }

        switch(WSAGETSELECTEVENT(lParam)){
        case FD_ACCEPT:
        sClient = accept(wParam, (struct sockaddr *)&client, &iAddrSize);
        // Add to the CPtrList
        // ......
        WSAAsyncSelect(sClient, hwnd, WM_SOCKET, FD_READ | FD_CLOSE);
        break;

        case FD_READ:
        ReadData(sock); // Paser the data.
        break;

        case FD_CLOSE:
        DeleteClient(sock); //Del from the CPtrList.
        break;

        default:
        break;
        }

        at last ,when add/del client, it will refresh onlines info to the Server's list control. May be it doesn't receive the FD_CLOSE message. but usually ,it has some few days ago results. I run in the Lan and use other Lan computer to test it, but can't found this problem. How about this ? Thanks for you reply !

        I Offline
        I Offline
        includeh10
        wrote on last edited by
        #3

        If client side closes normally, Close-event will be sent to server. But, if internet or network connect-line breaks or some odd things happen, Close-event will not be sent to server. in your test, you closed client socket normally, so you can't find problem. try to plug out connect cable to see what happens.

        W 1 Reply Last reply
        0
        • I includeh10

          If client side closes normally, Close-event will be sent to server. But, if internet or network connect-line breaks or some odd things happen, Close-event will not be sent to server. in your test, you closed client socket normally, so you can't find problem. try to plug out connect cable to see what happens.

          W Offline
          W Offline
          wangningyu
          wrote on last edited by
          #4

          may be is right , but is there any way to fix it ?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups