Send multicast datagram

Discuss client development (or even MPD development if you feel so inclined), ask questions about the client libs, MPD feature requests from client developers, etc...
Post Reply
skidoo
Posts: 200
Joined: April 28th, 2013, 10:06 pm
Location: Western Germany

Send multicast datagram

Post by skidoo »

Maybe stupid question but I do not get it.

Want to send an udp datagram to multicast address using MPD's internal API.

Code: Select all

SocketDescriptor MySocketDesc;
        if (!MySocketDesc.Create(AF_INET, SOCK_DGRAM, IPPROTO_IP))
        {
// error
        }
Ok there is a socket descriptor. But MySocketDesc.Write() requires SocketAddress. But how to initialise? Plain C uses sockaddr_in - what is the MPD way?

max
Forum team
Posts: 1063
Joined: January 15th, 2013, 3:43 pm

Re: Send multicast datagram

Post by max »

A "SocketAddress" is just a wrapper for "struct sockaddr" (it even has a constructor to initialize it with a "struct sockaddr"), and the rest is normal C knowledge.
But there's also the class "IPv4Address" which is implicitly convertible to "SocketAddress", and that class may be easier for you to handle. It can be initialized with a "struct sockaddr_in", but can also be initialized with IPv4 octets plus port, no fiddling with big-endian.

MPD uses those abstractions because I found the normal socket API to be cumbersome and error prone. And not portable - MPD's classes work on Windows (WinSock) as well.

skidoo
Posts: 200
Joined: April 28th, 2013, 10:06 pm
Location: Western Germany

Re: Send multicast datagram

Post by skidoo »

But there's also the class "IPv4Address" which is implicitly convertible to "SocketAddress", and that class may be easier for you to handle. It can be initialized with a "struct sockaddr_in", but can also be initialized with IPv4 octets plus port, no fiddling with big-endian.
That's how it worked. Thank you, Max :)

Post Reply