I am trying to code a simple client server application using the WSAAsyncSelect socket model. It is giving me some troubles that may best be described 'screwed up'. I connect to the loopback address with my client, and I get an FD_CONNECT and FD_WRITE notifications, but my server gets nothing! It's hard to be succinct about this problem, so I'm giving three tiers of information: what I see to be the problem, the main source files, and both the client and server projects.

In my client I do something like:

Code:
            ADDRINFOT * result = 0, hints = { 0 };

            hints.ai_family = AF_UNSPEC;
            hints.ai_socktype = SOCK_STREAM;
            hints.ai_protocol = IPPROTO_TCP;

            ret = ::GetAddrInfo( TEXT("127.0.0.1"), 
                TEXT("4337"), &hints, &result );

            ...


            ret = ::WSAAsyncSelect( sock, window, WM_SOCKET,
                FD_CONNECT | FD_READ | FD_WRITE | FD_CLOSE );

            ret = connect( sock, result->ai_addr, sizeof(sockaddr) );
            if( ret == SOCKET_ERROR && ::WSAGetLastError() != WSAEWOULDBLOCK )
            {
                // cleanup
                return -1;
            }
And then just print a 'howdy-doody' if I get my 'WM_SOCKET' message (which I get on FD_CONNECT and for FD_WRITE). In my server, I do something like:

Code:
    bool addrResult = false;

    sockaddr_in * us;
    SOCKET listener;

    ADDRINFOT * result = 0, hints = { 0 };

    hints.ai_family = AF_INET;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_protocol = IPPROTO_TCP;
    hints.ai_flags = AI_PASSIVE;

    ret = ::GetAddrInfo( NULL, TEXT("4337"), &hints, &result );
    if( ret != 0 )
    {
        dout << ErrorMessage( TEXT("WinMain"), ret ) << TEXT("\n");

        us = new sockaddr_in;

        us->sin_addr.S_un.S_addr = inet_addr( "127.0.0.1" );
        us->sin_family = AF_INET;
        us->sin_port = htons( static_cast< u_short >( 4337 ) );
        
        listener = ::WSASocket
            ( AF_INET, SOCK_STREAM, IPPROTO_TCP, 0, 0, 0 );
    }
    else
    {
        us = (sockaddr_in *) result->ai_addr;

        listener = ::WSASocket
            ( result->ai_family, result->ai_socktype, 
            result->ai_protocol, 0, 0, 0 );

        addrResult = true;
    }

    ret = ::bind( listener, reinterpret_cast< sockaddr * >(us), sizeof(*us) );

    ret = ::WSAAsyncSelect( listener, window->getHwnd(), WM_LISTENING,
        FD_CONNECT | FD_READ | FD_WRITE | FD_CLOSE );

    ret = ::listen( listener, 10 );
And again give myself a howdy-doody if I get a WM_LISTENING message. I never recieve one! My server program gives no debug output or indication of an error (I do extensive checking for errors in the real source), yet my client thinks it's connected (recieves FD_CONNECT and FD_WRITE notifications. I can WSASend successfully on FD_WRITE, but it does no good)! Does anyone know what could be going on?

Source and stuff to assist you:

http://zxcvbn.t35.com/ServerMain.cpp
http://zxcvbn.t35.com/ClientMain.cpp

http://zxcvbn.t35.com/Server.zip
http://zxcvbn.t35.com/Client.zip