vendredi 21 août 2020

How does one read data from a qtcpsocket

How do i go about reading data from a socket as the server. All have seen is writing servers, and read clients. Using readall() give strange results like crashes, or say i send "TEST:ggm" and "TEST2:WJX" i sometimes get "TEST:ggmTEST2:WJX", while other times the right reasult "TEST:ggm" and "TEST2:WJX" what am i missing here? The code used for initializing

qSocket = Server->nextPendingConnection();// qSocket is a QTcpSocket*
connect(qSocket, &QTcpSocket::disconnected, this, &MainWindow::SocketDisconnected);
if(std::string(qSocket->readAll().data()).compare("HFDFUJ") != 0) // Pass not safe i know.
{
   emit SocketDisconnected(); // disconnects socket
}
connect(qSocket, &QTcpSocket::readyRead, this, &SocketHandler);

Now what should i put in the readyRead fuction to read one message at a time

Aucun commentaire:

Enregistrer un commentaire