ste*_*225 10 c++ boost multicast
我有一个非常简单的boost :: asio套接字发送多播消息的包装器:
// header
class MulticastSender
{
public:
/// Constructor
/// @param ip - The multicast address to broadcast on
/// @param port - The multicast port to broadcast on
MulticastSender(const String& ip, const UInt16 port);
/// Sends a multicast message
/// @param msg - The message to send
/// @param size - The size of the message (in bytes)
/// @return number of bytes sent
size_t send(const void* msg, const size_t size);
private:
boost::asio::io_service m_service;
boost::asio::ip::udp::endpoint m_endpoint;
boost::asio::ip::udp::socket m_socket;
};
// implementation
inline MulticastSender::MulticastSender(const String& ip, const UInt16 port) :
m_endpoint(boost::asio::ip::address_v4::from_string(ip), port),
m_socket(m_service, m_endpoint.protocol())
{
m_socket.set_option(boost::asio::socket_base::send_buffer_size(8 * 1024 * 1024));
m_socket.set_option(boost::asio::socket_base::broadcast(true));
m_socket.set_option(boost::asio::socket_base::reuse_address(true));
}
inline size_t MulticastSender::send(const void* msg, const size_t size)
{
try
{
return m_socket.send_to(boost::asio::buffer(msg, size), m_endpoint);
}
catch (const std::exception& e)
{
setError(e.what());
}
return 0;
}
// read and send a message
MulticastSender sender(ip, port);
while(readFile(&msg)) sender.send(&msg, sizeof(msg));
Run Code Online (Sandbox Code Playgroud)
在使用Visual Studio 2013在Windows 7上编译时,我在Ubuntu 14.04~100 MB/s上获得~11 MB/s的吞吐量.我添加了计时器,并能够验证该send(...)方法是罪魁祸首.
我尝试启用和不启用防病毒,并尝试禁用其他一些服务,没有运气.有些我无法禁用由于计算机上的权限,如防火墙.
我假设Windows上运行的服务存在干扰,或者我的实现缺少影响Windows而不是Linux的应用程序.
关于可能引起注意的任何想法都将受到赞赏
windows和ubuntu是在同一台机器上运行吗?
如果没有,您的 Windows 机器似乎受到 100Mbit 以太网的限制,而 ubuntu 机器似乎可以使用 1Gbit 以太网。
(如果这不是问题的原因,我很抱歉发布一个答案而不是发表评论。但我无法这样做,而且你的代码很简单,数据速率非常明显[11*8MB/s ~ 100Mbit/s 和 100MB/s ~ 800Mbit/s]。我只是不得不做出这个提示......)
| 归档时间: |
|
| 查看次数: |
687 次 |
| 最近记录: |