Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void MainWindow::performRead()
- {
- QTcpSocket * sock = static_cast<QTcpSocket*>(this->sender());
- if (key == 0)
- {
- busy = true;
- QString recv(sock->readLine());
- key = recv.toInt();
- qDebug() << "Cheia este " << key;
- char * response = enc_dec("#AUTH|admin|admin",strlen("#AUTH|admin|admin"),key);
- sock->write(response);
- }
- else
- {
- busy = true;
- while (sock->bytesAvailable() > 0)
- {
- unsigned short word;
- sock->read((char*)(&word),2);
- qDebug()<<word;
- QByteArray bts = sock->read(word);
- char * decodat = enc_dec((char*)bts.data(),bts.length() - 2,key);
- char testx[2];
- sock->peek(&testx[0],2);
- qDebug() << decodat;
- }
- }
- busy = false;
- }
- void MainWindow::on_pushButton_clicked()
- {
- if (!busy)
- {
- key = 0;
- QTcpSocket * sock = new QTcpSocket();
- connect(sock,SIGNAL(readyRead()),this,SLOT(performRead()));
- sock->connectToHost("194.110.212.46",6550);
- }
- else qDebug()<<"Can't you see I am busy??" << endl;
- }
- char * enc_dec(char * str,int len, int key)
- {
- unsigned char keys[2];
- keys[0] = (unsigned char)key;
- keys[1] = keys[0] ^ 255;
- char * nou = new char[len + 1];
- nou[len] = '