Again with CAsyncSocket
I'm again with my attemp of implement a CAsyncSocket class to my
project.
I started from 0 again and have a class (MySocket:public CAsyncSocket)
that has to manage the connections.
The constructor creates the server socket:
MySocket::MySocket()
{
//CAsyncSocket* pServer = new CAsyncSocket;
this->numclients = 0;
int nPort = 15000;
int ret = this->Create( 15000 );
if( Listen()==FALSE )
{
//ERROR
}
else
{
//NO ERROR
}
}
This opens my server and starts listening connections:
void MySocket::OnAccept(int nErrorCode)
{
CAsyncSocket* client = new CAsyncSocket();
if( Accept( *client ) )
{
CString strIP;
UINT port;
this->GetSockName( strIP, port );
AfxMessageBox( _T("Client connected: " + strIP ) );
}
else
{
AfxMessageBox( "ERROR");
}
CAsyncSocket::OnAccept(nErrorCode);
}
Here comes my first doubt. To accept multiple connections... I'm doing
correctly?? I tried and every client seems to connect.
Now, for the sending data part:
I use Send( "SOME STRING", strlen("SOME STRING") );
But this does not sends anything (I think).
I've readed the MSDN examples, http://www.flounder.com/mvp_tips.htm,
googling and none clear my mind.
PD: I know that exist TRACE() but I use temporaly AfxMessageBox for
now.