This is a discussion on WSA_INVALID_HANDLE Problem within the Networking/Device Communication forums, part of the General Programming Boards category; Sockets are started to annoy me now. A SOCKET is just a u_int correct? So why is it that whenever ...

  1. #1
    Rat with a C++ compiler Rodaxoleaux's Avatar
    Join Date
    Sep 2011


    Sockets are started to annoy me now. A SOCKET is just a u_int correct? So why is it that whenever I try to make a SOCKET == another SOCKET, doing operations on it always returns errors, and if I pass them into classes and member functions, they always return errors?

    Such as like this:

    SOCKET newConn = lSocket.Accept(); 
            if (newConn != INVALID_SOCKET)
                Socket ServerSocket(newConn);
                *StatusLogBox << "Attempted connection located.";
                *StatusLogBox << "Receiving Welcome Packet...";
                string received = ServerSocket.Receive();
                if ( == 0)
                    *StatusLogBox << "Welcome Packet Received.";
                    int a = ServerSocket.Send(RKL_ACCEPTED_CONN);
                    i_Client->AddServer(newConn); //SOCKET is added to a vector as part of a globally declared class instance
                    EventQueue->ThrowEvent(EVNT_NEW_INSTALL,new NewInstallEvent(ServerSocket.GetIP(),ServerSocket));
                    *StatusLogBox << "v Connection terminated.";
            for (UINT i=0;i<i_Client->GetNumInstalls();i++)
                if (i_Client->IsDataWaiting(i)) //Problem
    the function's send function (here) returns -1.

    bool Client::IsDataWaiting(UINT index)
        bool found = false; //found at least one server with data waiting
        SOCKET sv = Servers[index];
        if(send(sv,RKL_DATA_WAITING.c_str(),RKL_DATA_WAITING.length(),0) == SOCKET_ERROR)
    Servers[0] (index==0), is the same newConn accept()ed SOCKET. Still the same number, but it returns -1 and WSAGetLastError() is... 6?

    Specified event object handle is invalid.An application attempts to use an event object, but the specified handle is not valid. Note that this error is returned by the operating system, so the error number may change in future releases of Windows.

    I've never seen that and when I looked, all I found was references to WSAWaitForMultipleEvents(), which I am not using. The handle should not have been deleted (although there is no handle so I'm even more confused.)

    I am at my last wit. What is up with SOCKETs?
    How to ask smart questions
    DWORD dwBytesOverwritten;
    BYTE rgucOverWrite[] = {0xe9,0,0,0,0};

  2. #2
    Join Date
    Dec 2007
    Does ServerSocket close or shutdown the SOCKET in its destructor? That object goes out of scope when you leave the
    if (newConn != INVALID_SOCKET)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 10-16-2008, 08:30 PM
  2. sturct/pointer problem, and fscanf problem
    By hiphop4reel in forum C Programming
    Replies: 6
    Last Post: 07-28-2008, 10:40 AM
  3. Replies: 27
    Last Post: 10-11-2006, 05:27 AM
  4. syntax linked list problem & struct problem
    By beely in forum C Programming
    Replies: 5
    Last Post: 11-11-2002, 09:14 AM
  5. Texture Problem(I got the NeHe tut working, but I have a problem)
    By SyntaxBubble in forum Game Programming
    Replies: 2
    Last Post: 12-02-2001, 10:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21