Advertisement

Goin crazy over this winsock problem

Started by December 11, 2002 09:14 PM
2 comments, last by MattCarpenter 22 years, 2 months ago
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?
//att
Well one problem I see, is that your OnReceive does this:

LPVOID* bufferw;
Receive(bufferw,100,0);

You''re writing to a memory location with an uninitialized pointer. This could be causing the receiver to crash, which on the server side looks like a disconnect.
Advertisement
Well, lol, it stopped disconnecting telnet from it. WHen I type a letter into telnet, the "Got Data" or whatever messagebox I had fires, but it won''t fire after that if i press any more keys :-/
//att
ahh nm, fixed it.
I forgot to put in the Receive function in there. I guess that event won''t fire unless the last time it did, it uses Receive
//att

This topic is closed to new replies.

Advertisement