Hi

I'm trying to use QUdpSocket on my Windows XP machine to receive datagrams for port number 514 (syslog). The problem is that the readyRead() signal is NEVER triggered; I have run every other udp samples (from QT SDK and books) and they all work. The only difference is that I'm trying to bind the socket to port 514 which is in the range of well-known port numbers (0-1023), maybe I need special rights to bind to this port number. The bind() call succeeds but readPendingDgrams() is never called. I have written a small Win32 C program using WinSock and I am able to receive the syslog datagrams, so it's not like I don't actually receive data. Below is the source code (Oh, I'm newbie to QT):

Qt Code:
  1. MainWindow::MainWindow(QWidget *parent)
  2. : QMainWindow(parent)
  3. {
  4. listView = new QListView(this);
  5. listModel = new QStringListModel();
  6. listModel->setStringList(listModelStrList);
  7. listView->setModel(listModel);
  8. setCentralWidget(listView);
  9. listView->setAlternatingRowColors(TRUE);
  10. udpSocket = new QUdpSocket(this);
  11. //udpSocket->bind(514, QUdpSocket::ShareAddress))
  12. if(false == udpSocket->bind(514))//udpSocket->bind(QHostAddress::Any/*QHostAddress::LocalHost*/, 514))
  13. {
  14. QMessageBox::warning(this, tr("LogViews"),
  15. tr("bind() error"),
  16. }
  17. else
  18. {
  19. QMessageBox::warning(this, tr("LogViews"),
  20. tr("bind() SUCCESS"),
  21. }
  22. connect(udpSocket, SIGNAL(readyRead()),
  23. this, SLOT(readPendingDgrams()));
  24. }
  25.  
  26. MainWindow::~MainWindow()
  27. {
  28.  
  29. }
  30.  
  31. void MainWindow::readPendingDgrams()
  32. {
  33. QMessageBox::warning(this, tr("LogViews"),
  34. tr("HAVE DATA !!!"),
  35. while(udpSocket->hasPendingDatagrams())
  36. {
  37. QByteArray datagram;
  38. datagram.resize(udpSocket->pendingDatagramSize());
  39. QHostAddress sender;
  40. quint16 senderPort;
  41. udpSocket->readDatagram(datagram.data(), datagram.size(),
  42. &sender, &senderPort);
  43. processDatagram(datagram);
  44. }
  45. }
  46.  
  47. void MainWindow::processDatagram(const QByteArray& dgram)
  48. {
  49. listModelStrList << dgram.data();
  50. }
To copy to clipboard, switch view to plain text mode