diff -r 2ddcc3e3e644 -r 523f1769f2bc QTfrontend/netudpwidget.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/netudpwidget.cpp Wed Feb 07 22:59:49 2007 +0000 @@ -0,0 +1,33 @@ +#include +#include + +#include "netudpwidget.h" + +#include + +HWNetUdpWidget::HWNetUdpWidget(QWidget* parent) : + QWidget(parent), mainLayout(this) +{ + serversList = new QListWidget(this); + mainLayout.addWidget(serversList); + pUdpSocket = new QUdpSocket(this); + + pUdpSocket->bind();//46632); + connect(pUdpSocket, SIGNAL(readyRead()), this, SLOT(onClientRead())); + pUdpSocket->writeDatagram("hedgewars client", QHostAddress::Broadcast, 46631); +} + +void HWNetUdpWidget::onClientRead() +{ + while (pUdpSocket->hasPendingDatagrams()) { + QByteArray datagram; + datagram.resize(pUdpSocket->pendingDatagramSize()); + QHostAddress clientAddr; + quint16 clientPort; + pUdpSocket->readDatagram(datagram.data(), datagram.size(), &clientAddr, &clientPort); + if(QString("%1").arg(datagram.data())==QString("hedgewars server")) { + qDebug() << "detected server at " << clientAddr << ":" << clientPort; + serversList->addItem(clientAddr.toString()); + } + } +}