Boost logo

Boost Users :

Subject: [Boost-users] No packets received with boost::asio::ip::udp::socket set to multicast group
From: Lennyk (lennyk430_at_[hidden])
Date: 2009-02-18 11:32:10


Hi,

I'm using boost 1.35 on a Linux machine.
I've written an application which creates a
boost::asio::ip::udp::socket, then binds to a certain local address &
port - and finally I've created an option to join a
boost::asio::ip::multicast::join_group.
All seems well, and I see the registration request through a network
sniffer.
BUT, when I try to receive packets after successfully joining the udp
multicast group - I get NOTHING!
Needless to say, I see tons of packets streaming through with the sniffer.

What am I doing WRONG?

Here's my code (just a test application):
using namespace std;
using namespace boost::asio;

int main(int argc, char *argv[])
{
    if (argc != 4) { // Test for correct number of parameters
        cerr << "Usage: " << argv[0] << " <Local Address> <Multicast
Address> <Port>" << endl;
        exit(1);
    }

    io_service m_io_service;
    ip::udp::socket m_socket(m_io_service);

    ip::address localAddress(ip::address_v4::from_string(argv[1]));
    ip::address multicastAddress(ip::address_v4::from_string(argv[2]));
    unsigned short port = atoi(argv[3]); // Second arg: port

    boost::system::error_code error;

    m_socket.open(ip::udp::v4());
    m_socket.bind(ip::udp::endpoint(localAddress, port), error);
    if (error)
    {
        cout << "bind error!" << endl;
        exit(1);
    }
    ip::multicast::join_group option(multicastAddress.to_v4(),
localAddress.to_v4());
    m_socket.set_option(option);

    vector<unsigned char> m_receiveBuffer;
    mutable_buffers_1 buf = buffer((void*)&m_receiveBuffer[0], 1024);

    int size = (int)m_socket.receive(buf, 0, error);
    if (error)
    {
        cout << "recv error!" << endl;
        exit(1);
    }

    return 0;
}

Thanks!
Lenny.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net