1

I've seen few threads about my question, but, still I can't seem to solve the problem, and the replies are not sufficient. So here is the task: I have 2 PCs. One must transmit 100 udp packets, with a simple test data, and the other machine must read the datagrams. My code is as follows:

The server:

m_socket.udp = new QUdpSocket(this);

if (m_socket.udp->bind(QHostAddress("192.168.32.154"), 1234)) {
    m_socket.udp->connectToHost(QHostAddress("192.168.32.154"), 1234);
    m_socket.udp->waitForConnected();
}
connect(m_socket.udp, SIGNAL(connected()),
        this, SLOT(handleConnection()));
connect(m_socket.udp, SIGNAL(readyRead()),
        this, SLOT(readyReadUdp()));

So... first - the binding to IP of machine 1 fails. I must not specify it's IP.

The client is simple:

p_socket = new QUdpSocket(this);
p_socket->connectToHost(QHostAddress("192.168.32.94"), 1234);
connect(p_socket, SIGNAL(connected()), this, SLOT(writeDgram()));
....
void writeDgram() {
    p_socket->write(QByteArray("test"));
}

So client code, as viewed in wireshark, comes to my server machine. But my server Qt code fails me. Any help here?

Ilian Zapryanov
  • 1,132
  • 2
  • 16
  • 28
  • Could you please be more specific? What do you see in wireshark? what do you mean by "first - the binding to IP of machine 1 fails" ? – Prabhu Oct 24 '16 at 13:30
  • I am binding to remote host, ex: 192.168.32.150 with port 1234, that would be machine 1, and from 192.168.32.150 I am sending 100 datagrams to the machine that is waiting. A simple example that connects 2 UDP sockets would be great. But the example must be between 2 computers. – Ilian Zapryanov Oct 24 '16 at 13:39
  • Is it that complicated to exchange few datagrams between 2 machines? No answers yet? – Ilian Zapryanov Oct 25 '16 at 07:02
  • Not at all. It should be fairly simple. – Prabhu Oct 25 '16 at 09:31
  • So how come that machine 1 is constantly sending UDP and wireshark catches them from machine 2, but my binding never emits the readyRead datagrams? – Ilian Zapryanov Oct 25 '16 at 10:01

2 Answers2

1

Yet, no one proposed that I can be firewalled. That was the problem. Removing the firewall solved this.

Ilian Zapryanov
  • 1,132
  • 2
  • 16
  • 28
0

I've setup another udp socket to handle incoming connections that way:

    void Server::handleConnection()
{
    std::cout << "Connected to host" << std::endl;
    m_inaddr = new QUdpSocket(this);
    connect(m_inaddr, SIGNAL(readyRead()),
            this, SLOT(readyReadUdp()));

    QHostAddress addr = m_socket.udp->peerAddress();
    quint16 port = m_socket.udp->peerPort();

    bool conn = m_inaddr->bind(45678);

    if (conn) {
        m_inaddr->connectToHost(addr, port);
        std::cout << "Bound to: " << addr.toString().toStdString()
                  << " port:"
                  << port << std::endl;
    }

}

But it seems it's not working the proper way. When I am connected, I can read the peer host and port, but the auxilary socket, for inaddress must be bound to what? I am getting confused with the UDP. [EDIT] Just to add that I never break in the readyReadUdp() slot, I`ve put a breakpoint there. The reader is standart one, but the slot is never called. So I guess there is nothing ready to read.

Ilian Zapryanov
  • 1,132
  • 2
  • 16
  • 28