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).
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
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?
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