i would like to know how to send and receive a broadcast msg if there are several devices connected in the same network (for example network address, 192.168.0.0). Please help!
i would like to know how to send and receive a broadcast msg if there are several devices connected in the same network (for example network address, 192.168.0.0). Please help!
i use the code bellow to broadcast,but i find there isn't any packet sent at all!!!
TInetAddr iAddrBroadcast;
iAddrBroadcast.Input ( _L("255.255.255.255"));
//iAddrBroadcast.NetBroadcast(iServerCommanderAddr2);
iAddrBroadcast.SetPort ( 10300);
iAddrBroadcast.SetFamily ( KInetAddrBroadcast); //
iSocket->SendTo( iBuffer, iAddrBroadcast, 0, iStatus );
You should not tamper with SetFamily. Personally I have never set it or seen it to be set to anything (I think it is the task of the given TSockAddr descendant), and it is absolutely sure that KInetAddrBroadcast is an address, not an address family.
now i change my code as bellow ,and capture packets by tool wireshark ,and i find these isn't any packet been captued.
TInetAddr iAddrBroadcast;
iAddrBroadcast.Input ( _L("255.255.255.255"));
iAddrBroadcast.SetPort ( 10300);
iAddrBroadcast.SetFamily ( KAfInet); //
iSocket->SendTo( iBuffer, iAddrBroadcast, 0, iStatus );
The constant appearance of line "TInetAddr iAddrBroadcast;" disturbs me, please confirm that it is actually a member variable.
Also note that this request has a completion code, have you checked iStatus in your RunL?
Just a minor comment: The "Input"-method already sets the address family correctly (you can use IPv6 addresses too). Using SetFamily should be omitted (it actually might mess up the work of Input method!).