i'm getting duplicate data on client-server communication... when sending for example 65502 (hex ffde), on socket i can see duplicate (ffdeffde..)..
to client.. wanna auth? client wanna authenticate???
question 67 op 1 67 = -122
"ffdeffde434301"
getting auth answer from client... checking
asking for authentication??? writing authme
sending auth question??? "ffdeffde4343010032000000010000000a000500e0010c00e 8e83d0010e83d0010e83d0010e83d0"
writing autha
auth passed
SERVER:
QByteArray auth;
QDataStream dsauth(&auth,QIODevice::ReadWrite);
....etc
indg_socket::indg_socket(QObject *parent) :
QTcpSocket(parent)
{
//generate random numbers
srand(time(NULL));
random1=rand()%256;
//sleep(3);
srand(time(NULL));
random2=rand()%256;
srand((time(NULL)+5));
oper=rand()%5;
result=computeauth(random1, random2, oper); //put 2 random numbers, random operation and compute result
dsauth << (quint16)65500;
dsauthme << (quint16)65501;
dsauthq << (quint16)65502;
dsautha << (quint16)65503;
dsuserkeys << (quint16)65504;
dsauthok << (quint16)65508;
dsauthfailure << (quint16)65509;
dsadmstatq << (quint16)65510;
isClientAuthenticated=false;
connect(this, SIGNAL(readyRead()), this, SLOT(readpackets()));
connect(this, SIGNAL(finished()), this, SLOT(deleteLater()));
}
void indg_socket::readpackets()
{
sockdata=this->readAll();
sockdata.truncate(100); //truncate if packet greater than 100 bytes
if(sockdata==authme){
qDebug() << "client wanna authenticate!!!";
qDebug() << "sending question " << random1 << " op" << oper << " " << random2 << " = " << result;
authq.clear();
dsauthq << (quint16)65502 << (quint8)random1 << (quint8)random2 << (quint8)oper;
qDebug() << authq.toHex();
this->write(authq, 40);
sockdata.clear();
return;
}
if(sockdata==autha){
qDebug() << "getting auth answer from client... checking";
qDebug() << "OK";
this->write(authok);
sockdata.clear();
return;
}
if(sockdata.startsWith(admstatq)){
qDebug() << "getting auth answer from client... checking";
qDebug() << "OK";
this->write(authok);
sockdata.clear();
return;
}
return;
}
CLIENT:
ait_socket::ait_socket(QObject *parent) :
QTcpSocket(parent)
{
dsauth << (quint16)65500;
dsauthme << (quint16)65501;
dsauthq << (quint16)65502;
dsautha << (quint16)65503;
dsuserkeys << (quint16)65504;
dsauthok << (quint16)65508;
dsauthfailure << (quint16)65509;
connect(this, SIGNAL(readyRead()), this, SLOT(readpackets()));
connect(this, SIGNAL(finished()), this, SLOT(deleteLater()));
}
void ait_socket::readpackets()
{
sockdata=this->readAll();
if(sockdata.startsWith(auth)){
qDebug() << "server asking for authentication!!!";
qDebug() << "OK, writing authme";
this->write(authme);
sockdata.clear();
return;
}
if(sockdata.startsWith(authq)){
qDebug() << "server sending auth question!!!";
qDebug() << sockdata.toHex();
qDebug() << "OK, writing autha";
this->write(autha);
sockdata.clear();
return;
}
if(sockdata.startsWith(authok)){
qDebug() << "auth passed!";
this->write(userkeys);
sockdata.clear();
return;
}
return;
}
Bookmarks