|
-
July 29th, 1999, 12:02 PM
#1
CAsyncSocket
Hi,
I have derived from CAsyncsocket and created a Datagram socket on some port, and implemented OnReceive, and i have tried sending data from other application, Only thing i want to know whether OnReceive message is posted for Datagram socket, if so, this is not working in my app, can you people put some points where i may gone wrong in implementing it.
Thanks,
M.Srinivas
-
July 29th, 1999, 12:20 PM
#2
Re: CAsyncSocket
Hi,
This is from the online help...
Example
void CMyAsyncSocket::OnReceive(int nErrorCode) // CMyAsyncSocket is
// derived from CAsyncSocket
{
static int i=0;
i++;
TCHAR buff[4096];
int nRead;
nRead = Receive(buff, 4096);
switch (nRead)
{
case 0:
Close();
break;
case SOCKET_ERROR:
if (GetLastError() != WSAEWOULDBLOCK)
{
AfxMessageBox ("Error occurred");
Close();
}
break;
default:
buff[nRead] = 0; //terminate the string
CString szTemp(buff);
m_strRecv += szTemp; // m_strRecv is a CString declared
// in CMyAsyncSocket
if (szTemp.CompareNoCase("bye") == 0 )
ShutDown();
}
CAsyncSocket::OnReceive(nErrorCode);
}
Regards,
Paul Belikian
-
July 29th, 1999, 05:07 PM
#3
Re: CAsyncSocket
Hi
Thanks for it,, but my problem is iam not getting the notification OnReceive() itself,.,,, infact
i kept the breakpoint at the begining of OnReceive which never occurs.
M.Srinivas
-
July 29th, 1999, 10:16 PM
#4
Re: CAsyncSocket
Oh,
How did you create the socket? And are you sure both applications are 'talking' on the
same port number? There really isn't much you need to do in the UDP server side.
Regards,
Paul Belikian
-
July 29th, 1999, 10:24 PM
#5
Re: CAsyncSocket
Hi again,
here is a code fragment out of one of my old apps. After the two functions,
your socket should be able to get data from a client.
// m_nDGramServerPort = port number, i.e. 0x3f
// m_pDGramSocket-> = Derived CAsyncSocket class
if(m_pDGramSocket->Create(m_nDGramServerPort, SOCK_DGRAM, 0)==0)
{
TRACE("CSockServer:: Initialize(...) Create Failed.\n");
return -1;
}
if(m_pDGramSocket->AsyncSelect(FD_READ|FD_WRITE)==0)
{
TRACE("CSockServer:: Initialize(...) AsyncSelect Failed.\n");
return -1;
}
This application worked fine. Check again that both sides are on the same port number.
Regards,
Paul Belikian
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|