Can not send messages from Windows

I have run SITL on an Ubuntu machine. I have executed the following command:
output add 192.168.1.21:14550
Where 192.168.1.21 is the IP address of an another machine that runs Windows 10

On the Windows machine I run MissionPlanner and make udp connection to the port 14550. Everything was fine. MissionPlanner starts to receive telemetries and it was able to send command successfully.

Now, I wrote some C++ code to connect via UDP. First I tried it on the Ubuntu machine and it run smoothly. I could connect, send and receive data.

I ran the same code on the Windows machine but it could only receive the telemetries . I could not send anything. When I try to send something, it does not generate any error message but the SITL does not receive anything.

I tried with a turned off firewall without any difference.

The problem does not seem from the code since it ran on Ubuntu well. It also does not seem from the connection since MissionPlanner could run!

I am posting the code anyway… Please any indicator is much appreciated.

This is the connection class:

class udp_connection {
public:
    udp_connection(unsigned short port);
    udp_connection(const udp_connection&) = default;
    ~udp_connection() = default;

    void open_and_bind() ;
    size_t send(const std::unique_ptr<mavlink_message_t>& message);
    bool receive(mavlink_message_t& msg) override;
private:
    unsigned short port_;
    boost::asio::io_service io_service_;
    boost::asio::ip::udp::socket socket_;
    boost::asio::ip::udp::endpoint endpoint_;
};

udp_connection::udp_connection(unsigned short port):
    port_(port),
    io_service_(),
    socket_(io_service_),
    endpoint_() {
}

void udp_connection::open_and_bind() {
    socket_.open(boost::asio::ip::udp::v4());
    socket_.bind( boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), port_));
}

size_t udp_connection::send(const std::unique_ptr<mavlink_message_t>& message) {
    return socket_.send_to(boost::asio::buffer(message.get(), sizeof(*message)), endpoint_);
}

bool udp_connection::receive(mavlink_message_t& msg) {
    std::vector<uint8_t> buffer(MAVLINK_MAX_PACKET_LEN);
    int i = 0;
    mavlink_status_t status;
    auto buffer_size = socket_.receive_from(boost::asio::buffer(buffer), endpoint_);

    if(buffer_size > 0) {
        //Do Sth
    }
    return false;
}

Notes:

  • I made sure that at least the HEARTBEAT message is received before I sent anything.
  • I am packing the mavlink messages with sys_id=1 trgt_id=1 (I tried [255,1] ,[0,0] with no luck too)
  • I tried the same code with a Real Drone. If I am excuting the code on Ubuntu machine connected with the drone, it works. If I am connection from a Windows machine, it does not.