Unsolved QudpSocket bind
-
HI,
socket = new QUdpSocket;
socket->bind(QHostAddress::Any,12345);In place of QHostAddress::Any ,need to add specific IP addresses (i.e., 192.168.1.18,192.168.1.19, 192.168.1.21) instead of accepting all the IP addresses.
I want to bind fixed 3 IP addresses only.
Thank you . -
Hi @yuvaram,
I want to bind fixed 3 IP addresses only.
As far as I know, the underlying OS sockets (on Linux, at least) only support one or all interfaces for a single bind. Qt probably doesn't extend on that.
So I think you would need to have three separate UDP binds, but you can connect them all to the same slot anyway, like:
MyClass::MyClass() { for (const QHostAddress &address, addresses) { QUdpSocket * const socket = new QUdpSocket(this); connect(socket, SIGNAL(readyRead()), this, SLOT(mySlot())); socket->bind(address, 12345); } } void MyClass::mySlot() { QUdpSocket * const socket = qobject_cast<QUdpSocket *>(sender()); Q_CHECK_PTR(socket); // do stuff with socket. }
Cheers.
-
@Paul-Colby
You mean that there it need to create 3 different sockets and bind it.
thank you. -
@yuvaram said:
You mean that there it need to create 3 different sockets and bind it.
Yep, you're right - I meant three separate sockets, each bound once :)
Cheers.