开发者

QUdpSocket. How to get the sender's ip address?

开发者 https://www.devze.com 2023-03-20 20:31 出处:网络
I 开发者_开发技巧have a server program that uses QUdpSocket. How do I find the ip address of the sender?From http://doc.qt.io/archives/4.6/qudpsocket.html#readDatagram,

I 开发者_开发技巧have a server program that uses QUdpSocket. How do I find the ip address of the sender?


From http://doc.qt.io/archives/4.6/qudpsocket.html#readDatagram,

qint64 QUdpSocket::readDatagram ( char * data, qint64 maxSize, QHostAddress * address = 0, quint16 * port = 0 )

You pass the addresses of a QHostAddress and a quint16 to the receive function, which get populated with the desired data.


You can get the sender address (and port) when you use the qint64 QUdpSocket::readDatagram ( char * data, qint64 maxSize, QHostAddress * address = 0, quint16 * port = 0 ) method.


You need to use readDatagram(). From the documentation :

The sender's host address and port is stored in *address and *port (unless the pointers are 0).

0

精彩评论

暂无评论...
验证码 换一张
取 消