bool Connection::readProtocolHeader() { if (transferTimerId) { killTimer(transferTimerId); transferTimerId = 0; } if (readDataIntoBuffer() <= 0) { transferTimerId = startTimer(TransferTimeout); return false; } if (buffer == "PING ") { currentDataType = Ping; } else if (buffer == "PONG ") { currentDataType = Pong; } else if (buffer == "MESSAGE ") { currentDataType = PlainText; } else if(buffer == "CARD "){ currentDataType = Card; } else if(buffer == "GROUP "){ currentDataType = Group; }else if (buffer == "GREETING ") { currentDataType = Greeting; } else { currentDataType = Undefined; abort(); return false; } buffer.clear(); numBytesForCurrentDataType = dataLengthForCurrentDataType(); return true; }
bool Connection::readProtocolHeader() { if (transferTimerId) { killTimer(transferTimerId); transferTimerId = 0; } if (readDataIntoBuffer() <= 0) { transferTimerId = startTimer(TransferTimeout); return false; } if (buffer == "CODE ") { qDebug()<<"Code buffer"; currentDataType = Code; } else if (buffer == "MESSAGE ") { qDebug()<<"mesaage buffer"; currentDataType = PlainText; } else if (buffer == "GREETING ") { qDebug()<<"greeting buffer"; currentDataType = Greeting; } else { qDebug()<<"undefined buffer"; currentDataType = Undefined; abort(); return false; } buffer.clear(); numBytesForCurrentDataType = dataLengthForCurrentDataType(); return true; }
bool Connection::readProtocolHeader() { if(m_transferTimerId) { killTimer(m_transferTimerId); m_transferTimerId = 0; } if(readDataIntoBuffer() <= 0) { m_transferTimerId = startTimer(TransferTimeout); return false; } if(m_buffer == "GREETING ") { m_currentDataType = Greeting; } else if(m_buffer == "DIRECTION ") { m_currentDataType = Direction; } else if(m_buffer == "GAMESTATE ") { m_currentDataType = GameState; } else if(m_buffer == "SELECTSERVER ") { m_currentDataType = SelectServer; } else if(m_buffer == "ACKNOWLEDGE ") { m_currentDataType = Acknowledge; } else if(m_buffer == "PLAYERADDR ") { m_currentDataType = PlayerAddr; } else { m_currentDataType = Undefined; abort(); return false; } m_buffer.clear(); m_numBytesForCurrentDataType = dataLengthForCurrentDataType(); return true; }
bool Connection::hasEnoughData() { if (numBytesForCurrentDataType <= 0) numBytesForCurrentDataType = dataLengthForCurrentDataType(); if (bytesAvailable() < numBytesForCurrentDataType || numBytesForCurrentDataType <= 0) { return false; } return true; }
bool DkConnection::hasEnoughData() { if (mNumBytesForCurrentDataType <= 0) { mNumBytesForCurrentDataType = dataLengthForCurrentDataType(); } //qDebug() << "numBytesForCurrentDataType:" << numBytesForCurrentDataType; //qDebug() << "bytesAvailable:" << bytesAvailable(); //qDebug() << "buffer size:" << buffer.size(); if (bytesAvailable() < mNumBytesForCurrentDataType || mNumBytesForCurrentDataType <= 0) { return false; } return true; }
bool DkConnection::readProtocolHeader() { QByteArray greetingBA = QByteArray("GREETING").append(SeparatorToken); QByteArray synchronizeBA = QByteArray("STARTSYNCHRONIZE").append(SeparatorToken); QByteArray disableSynchronizeBA = QByteArray("STOPSYNCHRONIZE").append(SeparatorToken); QByteArray newtitleBA = QByteArray("NEWTITLE").append(SeparatorToken); QByteArray newtransformBA = QByteArray("NEWTRANSFORM").append(SeparatorToken); QByteArray newpositionBA = QByteArray("NEWPOSITION").append(SeparatorToken); QByteArray newFileBA = QByteArray("NEWFILE").append(SeparatorToken); QByteArray goodbyeBA = QByteArray("GOODBYE").append(SeparatorToken); if (mBuffer == greetingBA) { //qDebug() << "Greeting received from:" << this->peerAddress() << ":" << this->peerPort(); mCurrentDataType = Greeting; } else if (mBuffer == synchronizeBA) { //qDebug() << "Synchronize received from:" << this->peerAddress() << ":" << this->peerPort(); mCurrentDataType = startSynchronize; } else if (mBuffer == disableSynchronizeBA) { //qDebug() << "StopSynchronize received from:" << this->peerAddress() << ":" << this->peerPort(); mCurrentDataType = stopSynchronize; } else if (mBuffer == newtitleBA) { //qDebug() << "New Title received from:" << this->peerAddress() << ":" << this->peerPort(); mCurrentDataType = newTitle; } else if (mBuffer == newtransformBA) { //qDebug() << "New Transform received from:" << this->peerAddress() << ":" << this->peerPort(); mCurrentDataType = newTransform; } else if (mBuffer == newpositionBA) { //qDebug() << "New Position received from:" << this->peerAddress() << ":" << this->peerPort(); mCurrentDataType = newPosition; } else if (mBuffer == newFileBA) { //qDebug() << "New File received from:" << this->peerAddress() << ":" << this->peerPort(); mCurrentDataType = newFile; } else if (mBuffer == goodbyeBA) { //qDebug() << "Goodbye received from:" << this->peerAddress() << ":" << this->peerPort(); mCurrentDataType = GoodBye; } else { qDebug() << QString(mBuffer); qDebug() << "Undefined received from:" << this->peerAddress() << ":" << this->peerPort(); mCurrentDataType = Undefined; //abort(); //return false; return true; } mBuffer.clear(); mNumBytesForCurrentDataType = dataLengthForCurrentDataType(); return true; }
bool Connection::hasEnoughData() { if (transferTimerId) { QObject::killTimer(transferTimerId); transferTimerId = 0; } if (numBytesForCurrentDataType <= 0) numBytesForCurrentDataType = dataLengthForCurrentDataType(); if (bytesAvailable() < numBytesForCurrentDataType || numBytesForCurrentDataType <= 0) { transferTimerId = startTimer(TransferTimeout); return false; } return true; }