English 中文(简体)
听助推库的乌普广播
原标题:Listening to an udp broadcast with the boost library

但至今为止我所找到的答案都无济于事。

Problem: I m trying to listen to a Velodyne HDL32 that sends its packets via UDP to my pc. The OS is 32-bit Ubuntu and Boost library v1.46.

我通过Wireshark获得的数据是这样的:

Time     | Source         | Destination   | Protocol | Length | Source Port | Destination Port
0.000000 | 192.168.17.212 | 192.168.3.255 | UDP      | 1248   | https       | opentable

但有了这个代码,我看不到任何数据(Port是正确的):

receiver(boost::asio::io_service& io_service,
  const boost::asio::ip::address& listen_address)
: m_socket(io_service)
{

boost::asio::ip::address ipAddr = boost::asio::ip::address_v4::any();
boost::asio::ip::udp::endpoint listen_endpoint(
         ipAddr, 2368);

m_socket.open(listen_endpoint.protocol());
m_socket.bind(listen_endpoint);

m_socket.async_receive_from(
    boost::asio::buffer(m_data, max_length), m_sender_endpoint,
    boost::bind(&receiver::handle_receive_from, this,
      boost::asio::placeholders::error,
      boost::asio::placeholders::bytes_transferred));
}

void handle_receive_from(const boost::system::error_code& error,
  size_t bytes_recvd)
{
std::cout << "receive" << bytes_recvd << std::endl;


  m_socket.async_receive_from(
      boost::asio::buffer(m_data, max_length), m_sender_endpoint,
      boost::bind(&receiver::handle_receive_from, this,
        boost::asio::placeholders::error,
        boost::asio::placeholders::bytes_transferred));
}

Can anyone identify a problem so far or do you need more information? I appreciate any help I can get.

NOTE: I m NOT running the program with root privileges!

Some thoughts: Could it be possible that boost::asio::ip::address_v4::any() won t listen to the IP ..*.255 when having subnetmask 255.255.255.0?

When using netcat, no data is shown as well. When I use Windows netcat it works quite fine. Same with Wireshark on Linux and Windows - works fine. Tried it with the as well, but with the same effect - no data.

最佳回答

谢谢大家帮我 代码没问题 但问题是在天线和网络的侧面

所有试图与威洛丁合作的其他人的解释如下:

The velodyne has it s own subnetwork (192.168.17.x). All recorded data is now send to the subnetwork 192.168.3.x by broadcast. Under normal circumstances the data should be received on all IPs in this subnet, but this seems not to be possible. The only IP you can receive data is the IP 255 and that just if you use one of these two solutions. (Or use windows or dump a file with wireshark)

< 强 > 1. 愚蠢的但可行的解决方案

设置192.168.3.1. 的网关。 是的, 没有, 但并不重要 。 从现在开始, 您将收到IP 255 的数据 。

<强 > 2. 清洁溶液

设置一条新的路线, 引导所有从 velodyne 子网到 192.168. 3.x 子网的交通 。

我真的不知道为什么它如此融洽,但是我们花了相当长的时间才发现这个“秘密”。 希望你们中的一些人能从我们这个虚伪的工作中获益。

问题回答

你试过设置广播选项吗?

// do this before binding
boost::asio::socket_base::broadcast option(true);
m_socket.set_option(option);




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签