Unsolved I want to use udp that specified IP to send data
-
UDP server needs bind the ip and port to receive data,how to specified the ip of the udp client?
now my pc has multiple IPs,I want to use the speified the ip to send data by udp.what should I do? -
Hi @spite ,
I'm not quite sure what you're after.
QUDPSocket has 2 functions to bind itself, derived from QAbstractSocket
bool QAbstractSocket::bind(const QHostAddress &address, quint16 port = 0, BindMode mode = DefaultForPlatform)
and
bool QAbstractSocket::bind(quint16 port = 0, BindMode mode = DefaultForPlatform)
I, for example, use this line
m_udpSocket->bind(8001, QUdpSocket::ShareAddress);
to lisen to all signals/data received at socket 8001 in my local Network.
and use
QUdpSocket::readyRead
to process/interpret all received data -
@spite said in I want to use udp that specified IP to send data:
how to specified the ip of the udp client?
you don't specify the IP address of the UDP client, you "bind" your UDP socket to an IP address and port in your machine, and it starts listening to client connections.
You may want to take a look at QUdpSocket documentation for more information -
@J.Hilk said in I want to use udp that specified IP to send data:
functions
My computer has a lot of IP,It has 192.168.168.100 、192.168.9.100、192.168.163.100 and so on. I want use the 192.168.163.100 to send a udp packet.
-
well sure, than use:
bind(QHostAddress("192.168.163.100"),myPort,QAbstractSocket::DefaultForPlatform);
or very similar to this.