jaganlal
May 22nd, 1999, 10:45 AM
Sir,
I would like to know how to Broadcast (Send & Receive
using SendTo() & ReceiveFrom() resp'ly) a message using
CAsyncSocket class. I have typed some coding here to
Send & Receive a message but it is not working properly.
Why? (ie; it is not sending & receiving the message).
Please guide me by modifying the coding given below by me.
Whether a DATAGRAM SOCKET will BLOCK or not?
Code for SENDING a message:
-------------------------------
void CSendView::OnSendTransmit() //Menu item
{
// TODO: Add your command handler code here
char buf[11] = "Teststring";
BOOL return_code;
CAsyncSocket sendto;
return_code = sendto.Create( 3000, SOCK_DGRAM, FD_READ | FD_CLOSE, NULL);
if( return_code == TRUE )
{
int sock_opt_value = 1;
return_code = sendto.SetSockOpt( SO_BROADCAST, &sock_opt_value,sizeof( BOOL ), SOL_SOCKET );
}
if(!sendto.SendTo(buf,10,3000,"255.255.255.0",0) == SOCKET_ERROR)
AfxMessageBox("Data not Send");
else
AfxMessageBox(buf);
}
------------------********-----------------
Code for RECEIVING the message:
-------------------------------
void CRecvView::OnRecvAccept() //Menu item
{
// TODO: Add your command handler code here
char buf[11];
strcpy(buf, "");
CString sock_add;
UINT my_port;
BOOL return_code;
CAsyncSocket srvr;
return_code = srvr.Create( 3000, SOCK_DGRAM, FD_WRITE | FD_CLOSE, NULL);
if(!srvr.ReceiveFrom(buf,10,sock_add,my_port,0))
AfxMessageBox("Receive Socket Failed");
else if(strlen(buf)>1)
AfxMessageBox(buf);
}
------------------********-----------------
Note:I have already received some of your coding with respect to my query.
But that style of coding doesn't suit me. So please send me details of coding
in accordance to the coding given above.
Thanking you,
Jaganlal
e-mail:jaganlal@hotmail.com
I would like to know how to Broadcast (Send & Receive
using SendTo() & ReceiveFrom() resp'ly) a message using
CAsyncSocket class. I have typed some coding here to
Send & Receive a message but it is not working properly.
Why? (ie; it is not sending & receiving the message).
Please guide me by modifying the coding given below by me.
Whether a DATAGRAM SOCKET will BLOCK or not?
Code for SENDING a message:
-------------------------------
void CSendView::OnSendTransmit() //Menu item
{
// TODO: Add your command handler code here
char buf[11] = "Teststring";
BOOL return_code;
CAsyncSocket sendto;
return_code = sendto.Create( 3000, SOCK_DGRAM, FD_READ | FD_CLOSE, NULL);
if( return_code == TRUE )
{
int sock_opt_value = 1;
return_code = sendto.SetSockOpt( SO_BROADCAST, &sock_opt_value,sizeof( BOOL ), SOL_SOCKET );
}
if(!sendto.SendTo(buf,10,3000,"255.255.255.0",0) == SOCKET_ERROR)
AfxMessageBox("Data not Send");
else
AfxMessageBox(buf);
}
------------------********-----------------
Code for RECEIVING the message:
-------------------------------
void CRecvView::OnRecvAccept() //Menu item
{
// TODO: Add your command handler code here
char buf[11];
strcpy(buf, "");
CString sock_add;
UINT my_port;
BOOL return_code;
CAsyncSocket srvr;
return_code = srvr.Create( 3000, SOCK_DGRAM, FD_WRITE | FD_CLOSE, NULL);
if(!srvr.ReceiveFrom(buf,10,sock_add,my_port,0))
AfxMessageBox("Receive Socket Failed");
else if(strlen(buf)>1)
AfxMessageBox(buf);
}
------------------********-----------------
Note:I have already received some of your coding with respect to my query.
But that style of coding doesn't suit me. So please send me details of coding
in accordance to the coding given above.
Thanking you,
Jaganlal
e-mail:jaganlal@hotmail.com