How to get the client's abort message with WSAAsyncSelect ?
-
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 !
-
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 !
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
-
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 !
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.
-
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.
may be is right , but is there any way to fix it ?