author | displacer |
Tue, 20 Feb 2007 22:34:42 +0000 | |
changeset 468 | 8403d6884707 |
parent 417 | bc7fea9abd9c |
child 486 | 7ea71cd3acd5 |
permissions | -rw-r--r-- |
413
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
1 |
#include <QUdpSocket> |
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
2 |
|
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
3 |
#include "netudpserver.h" |
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
4 |
|
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
5 |
HWNetUdpServer::HWNetUdpServer(QObject* parent) : |
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
6 |
QObject(parent) |
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
7 |
{ |
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
8 |
pUdpSocket = new QUdpSocket(this); |
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
9 |
pUdpSocket->bind(46631); |
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
10 |
|
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
11 |
connect(pUdpSocket, SIGNAL(readyRead()), this, SLOT(onClientRead())); |
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
12 |
|
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
13 |
} |
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
14 |
|
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
15 |
void HWNetUdpServer::onClientRead() |
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
16 |
{ |
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
17 |
while (pUdpSocket->hasPendingDatagrams()) { |
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
18 |
QByteArray datagram; |
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
19 |
datagram.resize(pUdpSocket->pendingDatagramSize()); |
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
20 |
QHostAddress clientAddr; |
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
21 |
quint16 clientPort; |
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
22 |
pUdpSocket->readDatagram(datagram.data(), datagram.size(), &clientAddr, &clientPort); |
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
23 |
if(QString("%1").arg(datagram.data())==QString("hedgewars client")) { |
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
24 |
// send answer to client |
417 | 25 |
pUdpSocket->writeDatagram("hedgewars server", clientAddr, clientPort); |
413
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
26 |
} |
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
27 |
} |
523f1769f2bc
udp server detecting experimental version (added files)
displacer
parents:
diff
changeset
|
28 |
} |