laasunde
February 25th, 2004, 07:46 AM
Need some help here. My OnReceive() methode doesnt seem to be working any longer. I've put a breakpoint in the method put it doesnt seem to execute. I use SendData() to try and trigger the event put nothing happens.
Would appreciate any help on how to debug this problem ? Im using the correct ip and portnr, also set FD_READ. I'm using udp socket so Listen() isnt needed.
//Header file
class CWinsocket: public CAsyncSocket
{
bool InitSocket(int port=0);
int SendData(char * Buffer, CString address, UINT port);
void OnReceive(int nErrorCode);
};
// Source code
bool CWinsocket::InitSocket(int port)
{
if (CAsyncSocket::Create(port, SOCK_DGRAM, FD_READ) == 0)
return false;
return true;
}
void CWinsocket::OnReceive(int nErrorCode)
{
char Buffer[1024];
int iReadBytes = CAsyncSocket::Receive((void*) Buffer, 1023);
CAsyncSocket::OnReceive(nErrorCode);
}
int CWinsocket::SendData(char * Buffer, CString address, UINT port)
{
int iSizeOfBuffer = 1024;
int iLength = CAsyncSocket::SendTo((void*) sendData, iSizeOfBuffer , port, (LPCTSTR) address);
delete Buffer;
if (iLength == SOCKET_ERROR || iLength != iSizeOfBuffer )
{
return -1;
}
return 0;
}
Would appreciate any help on how to debug this problem ? Im using the correct ip and portnr, also set FD_READ. I'm using udp socket so Listen() isnt needed.
//Header file
class CWinsocket: public CAsyncSocket
{
bool InitSocket(int port=0);
int SendData(char * Buffer, CString address, UINT port);
void OnReceive(int nErrorCode);
};
// Source code
bool CWinsocket::InitSocket(int port)
{
if (CAsyncSocket::Create(port, SOCK_DGRAM, FD_READ) == 0)
return false;
return true;
}
void CWinsocket::OnReceive(int nErrorCode)
{
char Buffer[1024];
int iReadBytes = CAsyncSocket::Receive((void*) Buffer, 1023);
CAsyncSocket::OnReceive(nErrorCode);
}
int CWinsocket::SendData(char * Buffer, CString address, UINT port)
{
int iSizeOfBuffer = 1024;
int iLength = CAsyncSocket::SendTo((void*) sendData, iSizeOfBuffer , port, (LPCTSTR) address);
delete Buffer;
if (iLength == SOCKET_ERROR || iLength != iSizeOfBuffer )
{
return -1;
}
return 0;
}