diff --git a/src/server/WebSocket.cpp b/src/server/WebSocket.cpp index 4a25955..753aee7 100644 --- a/src/server/WebSocket.cpp +++ b/src/server/WebSocket.cpp @@ -361,16 +361,47 @@ void WebSocket::EvaluateMessage(const QString &msg){ //qDebug() << " - Done with Text Message"; } +void WebSocket::ParseIncoming(){ + bool found = false; + + // Check if we have a complete JSON request waiting to be parsed + QString JsonRequest; + for ( int i = 0; i 128000 ) { + incomingbuffer=""; + return; + } + + // If we found a valid JSON request, but still have data, check for + // a second request waiting in the buffer + if ( found && incomingbuffer.size() > 2 ) + ParseIncoming(); +} + void WebSocket::EvaluateTcpMessage(){ //Need to read the data from the Tcp socket and turn it into a string //qDebug() << "New TCP Message:"; if(idletimer->isActive()){ idletimer->stop(); } - QString msg = QString(TSOCKET->readAll()); - for(int i=0; i<5 && !msg.endsWith("}"); i++){ - usleep(10000); //10ms - msg.append( QString(TSOCKET->readAll()) ); - } - EvaluateREST(msg ); + incomingbuffer.append(QString(TSOCKET->read(128000))); + + // Check for JSON in this incoming data + ParseIncoming(); + idletimer->start(); //qDebug() << " - Done with TCP Message"; } diff --git a/src/server/WebSocket.h b/src/server/WebSocket.h index 6d8d173..46164cd 100644 --- a/src/server/WebSocket.h +++ b/src/server/WebSocket.h @@ -29,6 +29,10 @@ private: QList ForwardEvents; void sendReply(QString msg); + // Where we store incoming Tcp data + QString incomingbuffer; + void ParseIncoming(); + //Main connection comminucations procedure void EvaluateREST(QString); //Text -> Rest/JSON struct void EvaluateRequest(const RestInputStruct&); // Parse Rest/JSON (does auth/events)