Hi,
my issue is with QUdpSocket.bind():
//udpSock->bind(QHostAddress("192.168.221.1"), 41000);
//bool bindResult = udpSock->bind(QHostAddress::AnyIPv4, quint16(41000));
bool bindResult = udpSock->bind();
qDebug() << udpSock->localAddress().toString();
qDebug() << udpSock->localPort();
qDebug() << bindResult;
qDebug() << udpSock->state();
udpSock = new QUdpSocket(this);
//udpSock->bind(QHostAddress("192.168.221.1"), 41000);
//bool bindResult = udpSock->bind(QHostAddress::AnyIPv4, quint16(41000));
bool bindResult = udpSock->bind();
qDebug() << udpSock->localAddress().toString();
qDebug() << udpSock->localPort();
qDebug() << bindResult;
qDebug() << udpSock->state();
To copy to clipboard, switch view to plain text mode
qDebug output for this code part:
"0.0.0.0"
59122
true
QAbstractSocket::BoundState
I send the UDP datagram using QUdpSocket.writeDatagram()
I am monitoring the packages with Wireshark and the package is sent successfully but the problem is that according to wireshark the source port is never the same as I've configured with bind (and so the receiver sends back an response to a wrong port). It seems randomly configured port because every time I re-run the UDP send the port is different.
The situation is the same if I use specific IP address and port (commented code part).
(I've tried this code on Win7 64bit and on Ubuntu 14.04 32bit, but the result is the same.)
Do I misunderstand something with bind()?
Added after 15 minutes:
Problem found:I referred to wrong QUdpSocket object.
Bookmarks