1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
void ThreadSend::send()
{
sockSend->writeDatagram( frame->getPaquet(), client->getIp(), client->getPort()+1);
//It is connection frame
if (client->getconnectionEstablished() == false)
{
int attempt = 0;
//Ensuite on attend le paquet d'acquitement qui va spécifier
//que la connexion s'est bien passé
while (client->getconnectionEstablished() == false)
{
//faire un if qui attend un temps donnée afin de renvoyer
//le paquet de connexion si il n'a pas été reçus
//Wait 250 milisecondes
QTest::qWait(250);
if (client->getconnectionEstablished() == false)
{
sockSend->writeDatagram( frame->getPaquet(), client->getIp(), client->getPort()+1);
}
//After ten attempt connection is not possible so error
if (attempt == 10)
{
emit fail("Connexion failed");
emit finished();
break;
}
attempt++;
}
}
else
{
// It is a acquittal frame
if (frame->getTypeFrame() == 0)
{
int attempt = 0;
//Ensuite on attend le paquet d'acquitement qui va spécifier
//que la connexion s'est bien passé
while (client->getAcquittal(frame->getNbFRame()) == false)
{
//Wait 250 milisecondes, before resend frame
QTest::qWait(250);
if (client->getAcquittal(frame->getNbFRame()) == false)
{
sockSend->writeDatagram( frame->getPaquet(), client->getIp(), client->getPort()+1);
}
//After ten attempt connection is not possible so error
if (attempt == 10)
{
// Warning can bug because qint are not a Qstring
//emit fail("Send frame n° : " + nbFrame + " failed, number of commande : ");
emit fail("Probleme d'envoie d'acquitement");
emit finished();
break;
}
attempt++;
}
}
else // It is other frame
{
int attempt = 0;
//Ensuite on attend le paquet d'acquitement qui va spécifier
//que la connexion s'est bien passé
while (client->getFrameAck(frame->getNbFRame()) == false)
{
//Wait 250 milisecondes, before resend frame
QTest::qWait(250);
if (client->getFrameAck(frame->getNbFRame()) == false)
{
sockSend->writeDatagram( frame->getPaquet(), client->getIp(), client->getPort()+1);
}
//After ten attempt connection is not possible so error
if (attempt == 10)
{
// Warning can bug because qint are not a Qstring
//emit fail("Send frame n° : " + nbFrame + " failed, number of commande : ");
emit fail("Probleme de frame");
emit finished();
break;
}
attempt++;
}
}
}
} |