QTfrontend/netudpserver.cpp
author displacer
Fri, 23 Feb 2007 13:15:04 +0000
changeset 484 3583f6289eee
parent 468 8403d6884707
child 486 7ea71cd3acd5
permissions -rw-r--r--
removed purged ethereal theme entry

#include <QUdpSocket>

#include "netudpserver.h"

HWNetUdpServer::HWNetUdpServer(QObject* parent) :
  QObject(parent)
{
  pUdpSocket = new QUdpSocket(this);
  pUdpSocket->bind(46631);

  connect(pUdpSocket, SIGNAL(readyRead()), this, SLOT(onClientRead()));
  
}

void HWNetUdpServer::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 client")) {
      // send answer to client
      pUdpSocket->writeDatagram("hedgewars server", clientAddr, clientPort);
    }
  }
}