socket OnReceive function not called
Hi,
I`m trying to get a working socket example using MFC.... at the moment
I`m not able to receive any kind of packets...
That`s what I`m doing step by step:
1) installing a thread:
m_pClientThread =
(CUdpClientThread*)AfxBeginThread(RUNTIME_CLASS(CUdpClientThread),
THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
m_pClientThread->SetTarget(AfxGetApp()->m_pMainWnd);
m_pClientThread->SetServerName(server);
m_pClientThread->SetPort(portnumber);
m_pClientThread->ResumeThread();
2) init socket
BOOL CUdpClientThread::InitInstance()
{
if(!CUdpSocketThread::InitInstance())
return FALSE;
if(!m_socket.Create(m_port, SOCK_DGRAM))
{ /* failed */
DWORD err = ::GetLastError();
ASSERT(target != NULL);
if(target != NULL)
target->PostMessage(UWM_NETWORK_ERROR, (WPARAM)err,
(LPARAM)::GetCurrentThreadId());
return FALSE;
} /* failed */
/* ******* */
LPCTSTR Data;
char buffer[20]= {10,10,101,10,10,10,10,10,10,10,10,10,10,10,10};
m_socket.SendTo(&buffer[0], strlen(&buffer[0]), m_port,
"2.255.255.255", 0);
return TRUE;
}
When I add the SendTo method to this function: the data will be
transmitted and after that the software will call the OnReceive
method....
Here are the class references:
class CUdpClientThread : public CUdpSocketThread
class CUdpSocketThread : public CWinThread
class UdpConnectSoc : public CAsyncSocket
And that`s the small OnReceive method - only for testing
void UdpConnectSoc::OnReceive(int nErrorCode)
{
if(nErrorCode != ERROR_SUCCESS)
{ /* had error */
AbortConnection(nErrorCode);
return;
} /* had error */
char buff[200];
int bytes_read = Receive(buff, 200);
buff[bytes_read] = 0; //terminate the string
}
Maybe someone of you will see some errors or have some information to
get a working example. I also tested some examples from microsoft
(http://support.microsoft.com/kb/185728/EN-US/) but these are also not
working... if I set this one up this app as server and port-nbr 5000 -
the programm will also not receive any message (the firewall is not
active)....
best regards
Bernd