コード例 #1
0
void SocketThread::processMessage(QString message)
{
    // ANY PROCESS HERE IS DONE IN THE SOCKET THREAD !
//    std::cout << tr("thread 0x%1 | %2")
//        .arg(QString::number((unsigned int)QThread::currentThreadId(), 16))
//        .arg(QString(message)).toStdString() << std::endl;

   auto request = QJsonDocument::fromJson(message.toLatin1()).toVariant().toMap();
   QVariantMap response;
   emit newFEMPRequest(request, response);
   auto responseJSON = QJsonDocument::fromVariant(response).toJson();
//   qDebug() << "response JSON: " << responseJSON;
   socket->write(QString::fromLatin1(responseJSON));
}
コード例 #2
0
ファイル: Server.cpp プロジェクト: USKamicadze/fefu-mmorpg
void Server::dataEnd()
{
  //    qDebug() << "request JSON: " << data_;
  QVariantMap request = QJsonDocument::fromJson(data_).toVariant().toMap();
  QVariantMap response;

  emit newFEMPRequest(request, response);

  response_->setHeader("Access-Control-Allow-Origin", "*");
  response_->setHeader("Content-Type", "application/json; charset=utf-8");
  response_->writeHead(QHttpResponse::STATUS_OK);
  auto responseJSON = QJsonDocument::fromVariant(response).toJson();
  //    qDebug() << "response JSON: " << responseJSON;
  response_->end(responseJSON);
  response_ = NULL;
  data_.clear();
}
コード例 #3
0
ファイル: WebSocketThread.cpp プロジェクト: dahin/fefu-mmorpg
void SocketThread::processMessage(QString message, bool lastFrame)
{
  if (!lastFrame)
  {
    qDebug() << "ws: non last frame";
  }
  // ANY PROCESS HERE IS DONE IN THE SOCKET THREAD !
  //    std::cout << tr("thread 0x%1 | %2")
  //        .arg(QString::number((unsigned int)QThread::currentThreadId(), 16))
  //        .arg(QString(message)).toStdString() << std::endl;

  auto request = QJsonDocument::fromJson(message.toLatin1()).toVariant().toMap();
  QVariantMap response;
  emit newFEMPRequest(request, response);
  auto responseJSON = QJsonDocument::fromVariant(response).toJson();
  //   qDebug() << "response JSON: " << responseJSON;

  //    static int pes = 1;
  //    pes++;
  //    while (true)
  //    {
  //        std::cerr << pes << std::endl;
  //        Sleep(1000);
  //        WaitForSingleObject(nullptr, 0);
  //    }
  //    pes++;
  //    std::cerr << "pes interruprt" << pes << std::endl;
  //   socket->write(QString::fromLatin1(responseJSON));
  QString textMessage = QString::fromLatin1(responseJSON);
  qint64 bytesSent = socket->sendTextMessage(textMessage);
  if (bytesSent != textMessage.size())
  {
    qDebug() << "Data was not sent. Data size: "
             << textMessage.size()
             << " Sent size: "
             << bytesSent;
  }
  //   socket->sendBinaryMessage(responseJSON);
}