qt - QTcpSocket doesn't read everything -
i trying use cryptopp qtcpsocket, encrypt username on client side, send through tcpsocket, , decrypt server side. here problem, qtcpsocket doesn't read message, can see server side expecting receive several packets 1 cipher, read method says whole message read in char*, don't see really.... here code sending cipher :
char size[5]; sprintf(size,"%d{",crypted_mess.size()); int written = 0; written = socket->write(size); written = socket->write(crypted_mess.c_str(),crypted_mess.size()+ 1); socket->waitforbyteswritten(crypted_mess.size()); string recovered = t.discryptor(crypted_mess) ;
and code decrypt (works fine client side without sending message) :
if(paquet_missing_size == 0) { current_message->clear(); was_read = socket->read(start_message,1000); int message_start = 0; while(start_message[message_start]!= '{') message_start++; char *size_total_string; size_total_string = (char*)malloc (message_start * sizeof (char)); for(int j = 0 ;j < message_start;j++ ){ size_total_string[j] = start_message[j]; } size_total_string[message_start] = '\0' ; paquet_missing_size = atoi(size_total_string); memcpy(read,start_message+message_start+1,was_read - message_start); } else was_read = socket->read(read,1000); // add read thing current_message if(was_read <= paquet_missing_size) { current_message->append(read, was_read); paquet_missing_size -= was_read; } else { current_message->append(read, paquet_missing_size); paquet_missing_size = 0; }
for purpose should use qbytearray qdatastream in order pass size of message first message.
hope help.
Comments
Post a Comment