当前位置: 首页>>代码示例>>C++>>正文


C++ Connection::SendMessage方法代码示例

本文整理汇总了C++中Connection::SendMessage方法的典型用法代码示例。如果您正苦于以下问题:C++ Connection::SendMessage方法的具体用法?C++ Connection::SendMessage怎么用?C++ Connection::SendMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Connection的用法示例。


在下文中一共展示了Connection::SendMessage方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: PerformOp

bool PerformOp(Connection &con, string client, string file, vector<string> slaves) {
  if (slaves.empty()) {
    return false;
  }
  // Send message to master slave(first) to prepare for client operation
  Message slave_prep(kSlavePrepareOp, SAFE_MESS);
  slave_prep.SetContent(SlaveOp{file, client, "", slaves});
  if (!con.SendMessage(slave_prep, slaves.front())) {
    cout << "Failed to prepare slaves for operation." << endl;
    return false;
  }

  // Wait slave to confirm operation and to inform the handler
  bool confirmed = false;
  string op_handler;
  Message tmp(0,0);
  if (con.GetMessage(kSlaveConfirmOp, kCreateTimeout, tmp)) {
    SlaveOp cop;
    tmp.GetContent(cop);
    confirmed = cop.client == client && cop.file_name == file;
    op_handler = tmp.sender();
  }

  // Slaves are not responding to prepare op
  if (!confirmed) {
    cout << "Storage slaves did not respond." << endl;
    return false;
  }

  Message client_prep(kClientPrepareOp, SAFE_MESS);
  client_prep.SetContent(ClientOp{file, op_handler});
  if (!con.SendMessage(client_prep, client)) {
    cout << "Failed to prepare client for operation." << endl;
    return false;
  }

  // Wait slave to confirm operation and to inform the handler
  confirmed = false;
  if (con.GetMessage(kFileOpResult, kCreateTimeout, tmp)) {
    ResultFileOp result;
    tmp.GetContent(result);
    confirmed = result.ok;
  }

  // Slave did not confirm
  if (!confirmed) {
    cout << "Storage slaves did not confirm operation." << endl;
  }
  return confirmed;
}
开发者ID:fernandodsl,项目名称:file_service,代码行数:50,代码来源:server_proxy.cpp

示例2: HandleGetLc

void DOTHeal::HandleGetLc(StringHash eventType, VariantMap& eventData)
{
	Node* sceneNode = (Node*)(eventData[GetLc::P_NODE].GetPtr());

	if (sceneNode == node_)
	{
		if (!targets_.Size())
		{
			return;
		}

		Connection* conn = (Connection*)(eventData[GetLc::P_CONNECTION].GetPtr());

		lc_->GetLagTime(conn);

		for (int x = 0; x < targets_.Size(); x++)
		{
			float timeRamp = targets_[x]->elapsedTime_ + lc_->lagTime_;

			lc_->msg_.Clear();
			lc_->msg_.WriteInt(lc_->clientID_);
			lc_->msg_.WriteString("DOTHeal");
			lc_->msg_.WriteInt(targets_[x]->clientID_);
			lc_->msg_.WriteFloat(timeRamp);
			conn->SendMessage(MSG_LCMSG, true, true, lc_->msg_);
		}
	}
}
开发者ID:practicing01,项目名称:Urho3DTemplate,代码行数:28,代码来源:DOTHeal.cpp

示例3: HandleClientConnect

void Server::HandleClientConnect(StringHash eventType, VariantMap& eventData)
{
	//LOGERRORF("client connected to server");

	using namespace NetworkMessage;

	Connection* sender = static_cast<Connection*>(eventData[P_CONNECTION].GetPtr());

	ClientData* newClient = new ClientData(clientIDCount_, sender, false);

	//Synchronize client data.
	for (int x = 0; x < clientData_.Size(); x++)
	{
		//Send the new client an old clients data
		msg_.Clear();
		msg_.WriteInt(clientData_[x]->clientID_);
		msg_.WriteBool(false);
		sender->SendMessage(MSG_NEWCLIENT, true, true, msg_);

		//Send the old client the new clients data.
		msg_.Clear();
		msg_.WriteInt(clientIDCount_);
		msg_.WriteBool(false);
		clientData_[x]->connection_->SendMessage(MSG_NEWCLIENT, true, true, msg_);

	}

	//Send the new client its data.
	clientData_.Push(newClient);
	msg_.Clear();
	msg_.WriteInt(clientIDCount_);
	msg_.WriteBool(true);
	sender->SendMessage(MSG_NEWCLIENT, true, true, msg_);

	//Send the new client the gamemode to load.
	msg_.Clear();
	msg_.WriteString(gamemodeName_.CString());
	sender->SendMessage(MSG_LOADGAMEMODE, true, true, msg_);

	clientIDCount_++;
}
开发者ID:practicing01,项目名称:DotsNetCrits,代码行数:41,代码来源:Server.cpp

示例4: HandleCreate

bool HandleCreate(const Message &msg, Connection &con) {
  bool succeeded = false;
  CreateFileOp op;
  auto client = msg.sender();
  try {
    msg.GetContent(op);
    cout << msg.sender() << " requested createop with args: " << op.file_name
         << " and " << op.redundancy << endl;
    if (!gFileMap.LockFile(op.file_name)) {
      cout << "Failed to lock entry. File was locked in the meantime." << endl;
      goto finish;
    }
    // get slaves associated with the file
    vector<string> slaves = GetFileSlaves(op.file_name);
    if (!slaves.empty()) {
      cout << "Create request failed. File does exist." << endl;
    } else {
      gSlavesLock.lock();
      for (auto &entry : gSlaves) {
        slaves.push_back(entry.first);
        if (slaves.size() == op.redundancy) break;
      }
      gSlavesLock.unlock();
      if (slaves.size() == op.redundancy) {
        succeeded = PerformOp(con, client, op.file_name, slaves);
      }
    }
    if (succeeded) {
      // insert the file on slaves
      gSlavesLock.lock();
      for (auto & slave : gSlaves) {
        if (find(begin(slaves), end(slaves), slave.first) != end(slaves)) {
          slave.second.push_back(op.file_name);
        }
      }
      gSlavesLock.unlock();
      SortSlaves();
    }

  } catch (...) {
    cout << "Invalid create request from " << msg.sender() << endl;
  }
  gFileMap.UnlockFile(op.file_name);

finish:
  Message res_msg(kFileOpResult, SAFE_MESS);
  ResultFileOp res{op.file_name, succeeded};
  res_msg.SetContent(res);
  if (!con.SendMessage(res_msg, client)) {
    cout << "Failed to inform client of op result." << endl;
  }
  return succeeded;
}
开发者ID:fernandodsl,项目名称:file_service,代码行数:53,代码来源:server_proxy.cpp

示例5: HandleRemove

bool HandleRemove(const Message &msg, Connection &con) {
  bool succeeded = false;
  bool locked = false;
  RemoveFileOp op;
  auto client = msg.sender();
  vector<string> slaves;
  try {
    msg.GetContent(op);
    cout << msg.sender() << " requested removeop with arg: " << op.file_name
         << endl;
    if (!(locked = gFileMap.LockFile(op.file_name))) {
      cout << "Failed to lock entry. File was locked in the meantime." << endl;
      goto finish;
    }
    // get slaves associated with the file
    slaves = GetFileSlaves(op.file_name);
    if (slaves.empty()) {
      cout << "Remove request failed. File does not exist." << endl;
    } else {
      succeeded = PerformOp(con, client, op.file_name, slaves);
    }

    if (succeeded) {
      // erases the files from slaves
      gSlavesLock.lock();
      for (auto & slave : gSlaves) {
        if (find(begin(slaves), end(slaves), slave.first) != end(slaves)) {
          auto &files = slave.second;
          files.erase(remove(begin(files), end(files), op.file_name), end(files));
        }
      }
      gSlavesLock.unlock();
      SortSlaves();
    }
  } catch (...) {
    cout << "Invalid create request from " << msg.sender() << endl;
  }
  if (locked) {
    gFileMap.UnlockFile(op.file_name);
  }
finish:
  Message res_msg(kFileOpResult, SAFE_MESS);
  ResultFileOp res{op.file_name, succeeded};
  res_msg.SetContent(res);
  if (!con.SendMessage(res_msg, client)) {
    cout << "Failed to inform client of op result." << endl;
  }
  return succeeded;
}
开发者ID:fernandodsl,项目名称:file_service,代码行数:49,代码来源:server_proxy.cpp

示例6: HandleGetLc

void Silence::HandleGetLc(StringHash eventType, VariantMap& eventData)
{
	Node* clientNode = (Node*)(eventData[GetLc::P_NODE].GetPtr());

	if (clientNode == node_)
	{
		Connection* conn = (Connection*)(eventData[GetLc::P_CONNECTION].GetPtr());

		msg_.Clear();
		msg_.WriteInt(clientID_);
		msg_.WriteString("Silence");
		msg_.WriteBool(silence_);
		conn->SendMessage(MSG_LCMSG, true, true, msg_);
	}
}
开发者ID:nonconforme,项目名称:Urho3DTemplate,代码行数:15,代码来源:Silence.cpp

示例7: HandleSend

void Chat::HandleSend(StringHash eventType, VariantMap& eventData)
{
    String text = textEdit_->GetText();
    if (text.Empty())
        return; // Do not send an empty message
    
    Network* network = GetSubsystem<Network>();
    Connection* serverConnection = network->GetServerConnection();
    
    if (serverConnection)
    {
        // A VectorBuffer object is convenient for constructing a message to send
        VectorBuffer msg;
        msg.WriteString(text);
        // Send the chat message as in-order and reliable
        serverConnection->SendMessage(MSG_CHAT, true, true, msg);
        // Empty the text edit after sending
        textEdit_->SetText(String::EMPTY);
    }
}
开发者ID:3dicc,项目名称:Urho3D,代码行数:20,代码来源:Chat.cpp

示例8: HandleRead

bool HandleRead(const Message &msg, Connection &con) {
  bool succeeded = false;
  bool locked = false;
  ReadFileOp op;
  auto client = msg.sender();
  vector<string> slaves;
  try {
    msg.GetContent(op);
    cout << msg.sender() << " requested readop with arg: " << op.file_name
         << endl;
    if (!(locked = gFileMap.LockFile(op.file_name))) {
      cout << "Failed to lock entry. File was locked in the meantime." << endl;
      goto finish;
    }
    // get slaves associated with the file
    slaves = GetFileSlaves(op.file_name);
    if (slaves.empty()) {
      cout << "Read request failed. File does not exist." << endl;
    } else {
      slaves.resize(1);
      succeeded = PerformOp(con, client, op.file_name, slaves);
    }
  } catch (...) {
    cout << "Invalid read request from " << msg.sender() << endl;
  }
  if (locked) {
    gFileMap.UnlockFile(op.file_name);
  }
finish:
  Message res_msg(kFileOpResult, SAFE_MESS);
  ResultFileOp res{op.file_name, succeeded};
  res_msg.SetContent(res);
  if (!con.SendMessage(res_msg, client)) {
    cout << "Failed to inform client of op result." << endl;
  }
  return succeeded;
}
开发者ID:fernandodsl,项目名称:file_service,代码行数:37,代码来源:server_proxy.cpp

示例9: SendMessage

void GameEconomicServerClientConsole::SendMessage(String Message)
{
    /// If sending message is empty
    if (Message.Empty())
    {
        return; // Do not send an empty message
    }

    /// Get connection
    Network* network = GetSubsystem<Network>();
    Connection* serverConnection = network->GetServerConnection();

    /// Send message only if serverconnection and connection is true
    if (serverConnection&&serverconnection)
    {
               // A VectorBuffer object is convenient for constructing a message to send
        VectorBuffer msg;
        msg.WriteString(Message);
        // Send the chat message as in-order and reliable
        serverConnection->SendMessage(NetMessageAdminClientSend, true, true, msg);
    }

    return;
}
开发者ID:vivienneanthony,项目名称:Urho3D-gameeconomic,代码行数:24,代码来源:GameEconomicServerClientConsole.cpp

示例10: if


//.........这里部分代码省略.........
				{
					/* yes, so don't resend */
					sendToThisPeer = false;
					break;
				}
			}

			if (sendToThisPeer)
			{
				local_sendto.push_back(this->pool.at(i));
			}
		}

		if (local_sendto.size() == 0)
		{
			wxLogVerbose("we cannot further distribute this broadcast");
			/* we have nothing to do */
			return;
		}

		/* prepare the message */
		for (i = 0; i < local_sendto.size(); i++)
		{
			RAIN::Connection *c = local_sendto.at(i);

			/* myval is a pointer into msg's via hash at the node containing our hash */
			myval->hash[c->pid->hash] = new BEnc::Dictionary();
		}

		/* now send it */
		for (i = 0; i < local_sendto.size(); i++)
		{
			wxLogVerbose("dispatching to %d (%s)", i, local_sendto.at(i)->pid->address.c_str());
			local_sendto.at(i)->SendMessage(msg);
		}
	} else if (msgdest->getString().Cmp("Peer") == 0) {
		BENC_SAFE_CAST(msg->headers["To"], msgto, String);
		if (!msgto)
			return;
		wxString to = msgto->getString();

		wxLogVerbose("    peer routing - to %s - searching local connections", CryptoHelper::HashToHex(to, true).c_str());

		for (int i = 0; i < this->pool.size(); i++)
		{
			if (this->pool.at(i) && this->pool.at(i)->isConnected)
			{
				if (RAIN::SafeStringsEq(this->pool.at(i)->pid->hash, to))
				{
					wxLogVerbose("        found connection");
					this->pool.at(i)->SendMessage(msg);
					return;
				}
			}
		}

		/* we're still here :(
		 * this implies we're not connected to the recipient of this message
		 * so we need to route it */
		if (!msg->headers.count("Route-Preload"))
		{
			/* we need to consult our routing manager to see if we know
			 * of a route to this host */
			RoutePath *rp;

			if (rp = this->app->router->GetBestRoute(to))
开发者ID:ctz,项目名称:rain,代码行数:67,代码来源:ConnectionPool.cpp

示例11: ServerHandleNetworkMessage

void PvPGM::ServerHandleNetworkMessage(StringHash eventType, VariantMap& eventData)
{
	using namespace NetworkMessage;

	int msgID = eventData[P_MESSAGEID].GetInt();

	Connection* sender = static_cast<Connection*>(eventData[P_CONNECTION].GetPtr());

	if (msgID == MSG_GAMEMODELOADED)
	{
		ServerSynchronizeScene(sender);
	}
	else if (msgID == MSG_GAMEMODEMSG)
	{
		const PODVector<unsigned char>& data = eventData[P_DATA].GetBuffer();
		MemoryBuffer msg(data);
		int messageID = msg.ReadInt();
		if (messageID == MSG_SCENELOADED_)
		{
			PlayerSB* player;

			//Create player on server.
			for (int x = 0; x < server_->clientData_.Size(); x++)
			{
				if (server_->clientData_[x]->connection_ == sender)
				{
					int index = Random( 0, spawnPoints_.Size() );
					victoria_ = spawnPoints_[index]->GetPosition();
					quarterOnion_ = spawnPoints_[index]->GetRotation();
					player = NewPlayer(server_->clientData_[x], "Witch3", victoria_, quarterOnion_);//Witch3 is the default model.
					break;
				}
			}

			for (int x = 0; x < players_.Size(); x++)
			{
				//Send client the existing players.
				msg_.Clear();
				msg_.WriteInt(MSG_NEWPLAYER_);
				msg_.WriteInt(players_[x]->clientData_->clientID_);
				msg_.WriteString(players_[x]->modelFilename_);
				msg_.WriteVector3(players_[x]->player_->GetPosition());
				msg_.WriteQuaternion(players_[x]->player_->GetRotation());

				sender->SendMessage(MSG_GAMEMODEMSG, true, true, msg_);

				if (sender != players_[x]->clientData_->connection_)
				{
					((GameMechanic*)(players_[x]))->receiver_ = sender;
					((GameMechanic*)(players_[x]))->clientID_ = players_[x]->clientData_->clientID_;
					players_[x]->ServerSync();

					//Send the existing players the client.
					msg_.Clear();
					msg_.WriteInt(MSG_NEWPLAYER_);
					msg_.WriteInt(player->clientData_->clientID_);
					msg_.WriteString(player->modelFilename_);
					msg_.WriteVector3(player->player_->GetPosition());
					msg_.WriteQuaternion(player->player_->GetRotation());

					players_[x]->clientData_->connection_->SendMessage(MSG_GAMEMODEMSG, true, true, msg_);
				}
			}
		}
		else if (messageID == MSG_RequestMechanicExecute_)
		{
			for (int x = 0; x < players_.Size(); x++)
			{
				if (players_[x]->clientData_->connection_ == sender)
				{
					float lagTime = ServerGetSenderLagTime(sender);
					lagTime += ServerGetSenderLagTime(sender);
					((GameMechanic*)(players_[x]))->message_ = &msg;
					((GameMechanic*)(players_[x]))->clientID_ = players_[x]->clientData_->clientID_;
					((GameMechanic*)(players_[x]))->lagTime_ = lagTime;
					players_[x]->RequestMechanicExecute();
					break;
				}
			}
		}
	}
}
开发者ID:practicing01,项目名称:DotsNetCrits,代码行数:82,代码来源:PvPGM.cpp


注:本文中的Connection::SendMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。