Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WSAAsyncSelect and error 10022 (invalid argument)

452 views
Skip to first unread message

Jan Hoeve

unread,
Aug 29, 2001, 8:47:51 AM8/29/01
to
i'm always getting 10022 error's with my server.

this is the code:
SOCKET listenSocket = WSASocket(AF_INET, SOCK_STREAM,0,
(LPWSAPROTOCOL_INFO)NULL, 0, WSA_FLAG_OVERLAPPED);
if (listenSocket == INVALID_SOCKET)
{
cout << "Fatal error: couldn't create a socket!" << endl;
return FALSE;
}


//stores the IP address, port and the address family in a structure
sockaddr_in local;
local.sin_addr.S_un.S_addr = inet_addr(localIP);
local.sin_port = htons(localPort);
local.sin_family = AF_INET;

//associates the above structure with the created listenSocket
if (bind(listenSocket,(struct sockaddr*)&local,sizeof(local)) ==
SOCKET_ERROR)
{
cout << "Fatal error: couldn't bind the IP and port to a socket!" <<
endl;
return FALSE;
}

//start listening at the listenSocket socket
if (listen(listenSocket,SOMAXCONN) == SOCKET_ERROR) {
cout << "Fatal error: unable to start listening at the socket!" <<
endl;
return FALSE;
}

if (WSAAsyncSelect(listenSocket, hWnd, WM_SOCKET,FD_CLOSE) ==
SOCKET_ERROR)
{
cout << "Fatal error: couldn't setup event notification for the
socket!" << " " << WSAGetLastError() << endl;
return FALSE;
}

in the last check (wsaasyncselect) i always get the 10022 error!

i searched in newsgroups, and nobody seemed to know the solution.
in:
http://groups.google.com/groups?hl=en&lr=lang_nl|lang_en&safe=off&th=d89ed5af7d7b94fd&seekm=7dudr8%247ph1%40news.ajou.ac.kr
i found that i had to use the WSA_FLAG_OVERLAPPED, but that doesn't
matter (still the error).

Peter Duniho

unread,
Aug 29, 2001, 4:04:17 PM8/29/01
to
"Jan Hoeve" <j.h...@tmlc.com> wrote in message
news:2b3729ba.01082...@posting.google.com...

> if (WSAAsyncSelect(listenSocket, hWnd, WM_SOCKET,FD_CLOSE) ==
> SOCKET_ERROR)

What are you using for hWnd and WM_SOCKET? Seems to me, given that Winsock
is complaining about the arguments, that there may be a problem with one of
your arguments. And those seem like the most likely candidates.

I don't know why this would cause a problem, but I'm curious why you don't
include FD_ACCEPT on your socket? Seems like if you're listening on the
socket, you'd be interested in getting notification of accept requests.

Pete


Jan Hoeve

unread,
Aug 31, 2001, 3:42:00 AM8/31/01
to
"Peter Duniho" <NpOeS...@NnOwSlPiAnMk.com> wrote in message news:<3b8d4ad1$1...@news.nwlink.com>...

well, that FD_ACCEPT was just a error of mine! :) changed into
FD_ACCEPT.
(no cure)
WM_SOCKET: #define WM_SOCKET (WM_USER + 1)
hWnd: simply a window handler. it seems to be correct, because the
windows shows if i do :
ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);

any idea?

Peter Duniho

unread,
Aug 31, 2001, 2:01:18 PM8/31/01
to
"Jan Hoeve" <j.h...@tmlc.com> wrote in message
news:2b3729ba.01083...@posting.google.com...
> any idea?

Ya got me. You'll have to look more closely at the docs for WSAAsyncSelect,
noting the various limitations and requirements for the socket and other
parameters, and determine for yourself what's going wrong.

For what it's worth, you probably ought to be using WM_APP + 1 for
WM_SOCKET, not WM_USER + 1. However, that surely has nothing to do with
your problem.

Pete


0 new messages