Indeed i'll be using udp sockets better since i prefer to send a broadcast to players looking for a challenger and i will be sending lots of messages however i dont know how to send and receive requests for playing ignoring my own message, i have this...
void startupDialog::readDatagrams(){
while( udpSocket->hasPendingDatagrams() ){
datagram.resize(udpSocket->pendingDatagramSize());
udpSocket->readDatagram(datagram.data(), datagram.size(), remoteHost);
if( qstrcmp(datagram.data(), "//SearchingPlayers") == 0 && remoteHost->toString() != ??? WTF ??? ){
playersFound++;
}
statusLabel2
->setText
(QString("PlayersFound :: %1").
arg(playersFound
));
}
}
void startupDialog::readDatagrams(){
QHostAddress *remoteHost = new QHostAddress;
while( udpSocket->hasPendingDatagrams() ){
QByteArray datagram;
datagram.resize(udpSocket->pendingDatagramSize());
udpSocket->readDatagram(datagram.data(), datagram.size(), remoteHost);
if( qstrcmp(datagram.data(), "//SearchingPlayers") == 0 && remoteHost->toString() != ??? WTF ??? ){
playersFound++;
}
statusLabel2->setText(QString("PlayersFound :: %1").arg(playersFound));
}
}
To copy to clipboard, switch view to plain text mode
And for the sender...
void startupDialog::sendDatagrams(){
statusLabel->setText("Looking for players...");
udpSocket->writeDatagram(datagram.data(), datagram.size(),
}
void startupDialog::sendDatagrams(){
statusLabel->setText("Looking for players...");
QByteArray datagram = "//SearchingPlayers";
udpSocket->writeDatagram(datagram.data(), datagram.size(),
QHostAddress::Broadcast, 45454);
}
To copy to clipboard, switch view to plain text mode
I dont know if this is the best way to find players but i want to avoid the message to myself so i dont know what to write instead of "WTF" can someone help? thanks
Bookmarks