socket通信的老问题,错误10038--->试图在一个非套接字上进行一个操作,帮我看下我的程序,就剩下这些分了- -!~
case WM_SERVERSOCKET1:
{
SOCKET s = (SOCKET) wParam;
if(WSAGETSELECTERROR(lParam))
{
MessageBox(NULL, TEXT("WM_SERVERSOCKET1 WSAGETSELECTERROR(lParam)"), NULL, MB_OK);
closesocket((SOCKET) wParam);
return 0;
}
switch(WSAGETSELECTEVENT(lParam))
{
case FD_ACCEPT:
{
MessageBox(NULL, TEXT("WM_SERVERSOCKET1 Begin FD_ACCEPT"), NULL, MB_OK);
int len = sizeof(SOCKADDR_IN);
SOCKET s2 = accept(s, (sockaddr*)&sa1, &len);
if(WSAAsyncSelect(s2, hWnd, UM_SOCK1, FD_READ | FD_CLOSE) == SOCKET_ERROR)
{
TCHAR szMsg[1024] = {0};
wsprintf(szMsg, TEXT("WSAAsyncSelect error %d"), WSAGetLastError());
MessageBox(NULL, szMsg, szMsg, MB_OK);
closesocket(s);
}
MessageBox(NULL, TEXT("WM_SERVERSOCKET1 After FD_ACCEPT"), NULL, MB_OK);
}
break;
case FD_CLOSE:
::closesocket(s);
break;
}
}
case UM_SOCK1:
{
//clientSocket1 = (SOCKET) wParam;
SOCKET s = (SOCKET)wParam;
if(WSAGETSELECTERROR(lParam))
{
MessageBox(NULL, TEXT("WSAGETSELECTERROR(lParam)"), TEXT("WSAGETSELECTERROR(lParam)"), MB_OK);
closesocket(s);
return 0;
}
switch(WSAGETSELECTEVENT(lParam))
{
case FD_READ:
{
MessageBox(NULL, TEXT("FD_READ"), TEXT("FD_READ"), MB_OK);
char szBuffer[1024]={0};
while(1)
{
ret = recv(s ,szBuffer,BUFFER_SIZE,0);
if(ret == 0)
{
MessageBox(NULL, TEXT("Ret == 0"), TEXT("Ret == 0"), NULL);
break;
}
else if(ret == SOCKET_ERROR)
{
DWORD error_no = WSAGetLastError();
TCHAR szMsg[1024] = {0};
wsprintf(szMsg, TEXT("Ret == SOCKET_ERROR error_no = %d"), error_no);
MessageBox(NULL, szMsg, szMsg, NULL);
//closesocket(s);
break;
}
}
}
为什么会出现题目中的错误呀!~~~~~~~~~~~~~~~~请赐教,,