Ok, I made my own class derived from the CAsyncSocket object, and that class stuff looks like this:
class CsckListen : public CAsyncSocket
{
DECLARE_DYNCREATE(CsckListen);
protected:
virtual void OnAccept(int nErrorCode);
virtual void OnReceive(int nErrorCode);
};
IMPLEMENT_DYNCREATE(CsckListen,CAsyncSocket);
void CsckListen::OnReceive(int nErrorCode)
{
CAsyncSocket::OnReceive(nErrorCode);
LPVOID* bufferw;
Receive(bufferw,100,0);
MessageBox(NULL,"Got Data","Socket Listener",MB_OK);
int err = GetLastError();
char buffer[200];
sprintf(buffer,"\n\nError: %i\n\n",err);
OutputDebugString(buffer);
}
CsckListen Sock;
CsckListen DataSock;
void CsckListen::OnAccept(int nErrorCode)
{
//CAsyncSocket::OnAccept(nErrorCode);
Accept(DataSock,NULL,NULL);
MessageBox(NULL,"Somebody Connected","Socket Listener",MB_OK);
};
and the code that sets up the Sock object (the sock used for listening) looks like this:
WSADATA temp;
WSAStartup(MAKEWORD(1,1),&temp);
bool test =Sock.Create(77,SOCK_STREAM,FD_READ|FD_ACCEPT|FD_WRITE|FD_CONNECT|FD_CLOSE);
//DataSock.Create(20);
if(test==true) { MessageBox("True",NULL,MB_OK); }
int err = Sock.GetLastError();
char buffer[255];
sprintf(buffer,"MaxSocks: %i\nDescription: %c",temp.iMaxSockets,temp.szDescription);
OutputDebugString(buffer);
//Listen
Sock.Listen();
It all works great, except IT DISCONNECTS WHATEVER''S CONNECTED TO (DataSock) when the CsckListen::OnReceive function fires. (This OnRecieve is my own function; it overides the CAsyncSocket::OnReceive so I can tell when I recieve data)
Anybody know why its doing this?