diff options
Diffstat (limited to 'examples/network/multicastsender')
-rw-r--r-- | examples/network/multicastsender/sender.cpp | 18 | ||||
-rw-r--r-- | examples/network/multicastsender/sender.h | 4 |
2 files changed, 21 insertions, 1 deletions
diff --git a/examples/network/multicastsender/sender.cpp b/examples/network/multicastsender/sender.cpp index 38d532c..7fa9750 100644 --- a/examples/network/multicastsender/sender.cpp +++ b/examples/network/multicastsender/sender.cpp @@ -48,7 +48,15 @@ Sender::Sender(QWidget *parent) { groupAddress = QHostAddress("239.255.43.21"); - statusLabel = new QLabel(tr("Ready to send datagrams to multicast group %1 on port 45454").arg(groupAddress.toString())); + statusLabel = new QLabel(tr("Ready to multicast datagrams to group %1 on port 45454").arg(groupAddress.toString())); + + ttlLabel = new QLabel(tr("TTL for multicast datagrams:")); + ttlSpinBox = new QSpinBox; + ttlSpinBox->setRange(0, 255); + + QHBoxLayout *ttlLayout = new QHBoxLayout; + ttlLayout->addWidget(ttlLabel); + ttlLayout->addWidget(ttlSpinBox); startButton = new QPushButton(tr("&Start")); quitButton = new QPushButton(tr("&Quit")); @@ -61,16 +69,24 @@ Sender::Sender(QWidget *parent) udpSocket = new QUdpSocket(this); messageNo = 1; + connect(ttlSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ttlChanged(int))); connect(startButton, SIGNAL(clicked()), this, SLOT(startSending())); connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); connect(timer, SIGNAL(timeout()), this, SLOT(sendDatagram())); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(statusLabel); + mainLayout->addLayout(ttlLayout); mainLayout->addWidget(buttonBox); setLayout(mainLayout); setWindowTitle(tr("Multicast Sender")); + ttlSpinBox->setValue(1); +} + +void Sender::ttlChanged(int newTtl) +{ + udpSocket->setSocketOption(QAbstractSocket::MulticastTtlOption, newTtl); } void Sender::startSending() diff --git a/examples/network/multicastsender/sender.h b/examples/network/multicastsender/sender.h index 176830b..f119883 100644 --- a/examples/network/multicastsender/sender.h +++ b/examples/network/multicastsender/sender.h @@ -50,6 +50,7 @@ class QLabel; class QPushButton; class QTimer; class QUdpSocket; +class QSpinBox; QT_END_NAMESPACE class Sender : public QDialog @@ -60,11 +61,14 @@ public: Sender(QWidget *parent = 0); private slots: + void ttlChanged(int newTtl); void startSending(); void sendDatagram(); private: QLabel *statusLabel; + QLabel *ttlLabel; + QSpinBox *ttlSpinBox; QPushButton *startButton; QPushButton *quitButton; QDialogButtonBox *buttonBox; |