Hello, I am trying to get data from a LAN-connected infrared camera.
I don't know how to receive packets from the external network.
Here's my code.

Qt Code:
  1. MyUDP::MyUDP(QObject *parent) :
  2. QObject(parent)
  3. {
  4. // create a QUDP socket
  5. socket = new QUdpSocket(this);
  6. socket_cam = new QUdpSocket(this);
  7. // The most common way to use QUdpSocket class is
  8. // to bind to an address and port using bind()
  9. // bool QAbstractSocket::bind(const QHostAddress & address,
  10. // quint16 port = 0, BindMode mode = DefaultForPlatform)
  11. socket->bind(QHostAddress::LocalHost, 1234);
  12.  
  13. connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
  14. }
  15.  
  16. void MyUDP::HelloUDP()
  17. {
  18. QByteArray Data;
  19.  
  20. QHostAddress camera_loc = QHostAddress("192.168.10.197");
  21. quint16 cameraPort = 32197;
  22.  
  23. qint64 deg_num = socket->readDatagram(Data.data() ,964, &camera_loc, &cameraPort);
  24. qDebug() << "Deg_num: " << deg_num; //this returns -1. Therefore, it seems it can't read any data from camera_loc.
  25. // Sends the datagram datagram
  26. // to the host address and at port.
  27. // qint64 QUdpSocket::writeDatagram(const QByteArray & datagram,
  28. // const QHostAddress & host, quint16 port)
  29. socket->writeDatagram(Data, QHostAddress::LocalHost, 1234);
  30. }
  31.  
  32. void MyUDP::readyRead()
  33. {
  34. // when data comes in
  35. QByteArray buffer;
  36. buffer.resize(socket->pendingDatagramSize());
  37.  
  38. QHostAddress sender = QHostAddress("192.168.10.197");
  39. quint16 senderPort = 32197;
  40.  
  41. // qint64 QUdpSocket::readDatagram(char * data, qint64 maxSize,
  42. // QHostAddress * address = 0, quint16 * port = 0)
  43. // Receives a datagram no larger than maxSize bytes and stores it in data.
  44. // The sender's host address and port is stored in *address and *port
  45. // (unless the pointers are 0).
  46.  
  47. socket->readDatagram(buffer.data(), buffer.size(),
  48. &sender, &senderPort);
  49. qDebug() << "Message from: " << sender.toString();
  50. qDebug() << "Message port: " << senderPort;
  51. qDebug() << "Message: " << buffer;
  52. }
To copy to clipboard, switch view to plain text mode 

I changed a little from Qt5 Tutorial QUdpSocket(https://www.bogotobogo.com/Qt/Qt5_QUdpSocket.php)
As I've seen on Wireshark, packets arrived correctly as I expected.
However, my code doesn't work as I expected. (readDatagram on camera_loc returns (-1))
According to other threads, we don't need to connect them because UDP communication doesn't need to make connections.
What I want to make with this code is as follow.

(0. Save data from the camera (192.168.10.197) on a variable using readDatagram) I am not sure this is a really necessary process...
1. Write data to buffer as written in this code (using writeDatagram function).

I could not find solutions even if I struggled.
I thought it would be easy but it wasn't ...
Any advice will be very grateful because I am a newbie to qt and UDP network.

Thanks in advance.

RadioKong