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:
Code:
SOCKET newConn = lSocket.Accept();
if (newConn != INVALID_SOCKET)
{
Socket ServerSocket(newConn);
ServerSocket.SetIP(lSocket.GetIP());
*StatusLogBox << "Attempted connection located.";
*StatusLogBox << "Receiving Welcome Packet...";
string received = ServerSocket.Receive();
if (received.compare(RKL_INSTALL_DATA) == 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
i_Client->AddIP(ServerSocket.GetIP());
EventQueue->ThrowEvent(EVNT_NEW_INSTALL,new NewInstallEvent(ServerSocket.GetIP(),ServerSocket));
}
else
{
*StatusLogBox << "v Connection terminated.";
ServerSocket.Drop();
}
}
lSocket.SetBlocking(true);
for (UINT i=0;i<i_Client->GetNumInstalls();i++)
{
if (i_Client->IsDataWaiting(i)) //Problem
the function's send function (here) returns -1.
Code:
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?