tags:

views:

132

answers:

2

Hi! all, I was trying to write a udp server who send an instance of a file to multiple clients.Now suppose any how I manage to know the address of those client statically(for the sake of simplicity) and now I want to send this packet to these addresses.So how exactly I need to fill the sockaddr structure to contain the address of these clients.I am taking an array of sockaddr structure(to contain client address) and trying to send at each one them at a time.Now problem is to fill the individual sockaddr structure to contain the client address. I was trying to do something like that

 sa[1].sin_family = AF_INET;
 sa[1].sin_addr.s_addr = htonl(INADDR_ANY);//should'nt I replace this INADDR_ANY with client ip??
 sa[1].sin_port = htons(50002);

Correct me if this is not the correct way. All your help in this regard will be highly appreciated.

With Thanks in advance,

Mawia

+1  A: 

sin_addr should be set to the destination address.

if (! inet_aton("1.2.3.4", &sa[1].sin_addr)) {
    // Give up all hope
}
// Everything is copacetic.
WhirlWind
Thanks a lot sir,for the reply.It was very very helpful. Thanks and thanks again!Thankyou!
mawia
+1  A: 

Looks like you're talking about multicast. It is a bit harder than trivial.

Take a look at this thread to discover how to subscribe to a multicast group (for the client side) and how to send multicast packets (for the server side). It is discussed using python, but only low-level wrappers around socket library are used, so it should be quite simple to translate examples to any language.

nailxx
Thanks for the reply!
mawia