void Socket::sendString(std::string const & iMessage) { zmq::message_t aZmqMessage(iMessage.size()); memcpy((void *) aZmqMessage.data(), iMessage.c_str(), iMessage.size()); try { m_zmqSocket->send(aZmqMessage); ORWELL_LOG_TRACE("Sent " << iMessage); } catch (...) { ORWELL_LOG_TRACE("Failed to send zmq message."); } }
void Socket::sendString(std::string const & iMessage) { zmq::message_t aZmqMessage(iMessage.size()); memcpy((void *) aZmqMessage.data(), iMessage.c_str(), iMessage.size()); m_zmqSocket->send(aZmqMessage); ORWELL_LOG_TRACE("Sent " << iMessage ); }
void Socket::send( RawMessage const & iMessage ) { string aMessage; aMessage += iMessage._routingId; aMessage += " "; aMessage += iMessage._type; aMessage += " "; aMessage += iMessage._payload; sendString(aMessage); ORWELL_LOG_TRACE("Sent " << aMessage.size() << " bytes : " << iMessage._type << "-"); }
void ProcessTimer::execute() { ORWELL_LOG_TRACE("ProcessTimer::execute : broadcast Gamestate"); GameState aGameState; aGameState.set_playing(m_game->getIsRunning()); if (m_game->getWinner()) { aGameState.set_winner(*m_game->getWinner()); } RawMessage aMessage("all_clients", "GameState", aGameState.SerializeAsString()); m_publisher->send( aMessage ); }
bool Socket::receiveString( std::string & oMessage, bool const iBlocking) { zmq::message_t aZmqMessage; int aFlags = 0; if (not iBlocking) { aFlags = ZMQ_NOBLOCK; } bool const aReceived = m_zmqSocket->recv(&aZmqMessage, aFlags); if (aReceived) { ORWELL_LOG_TRACE("message received"); oMessage = string(static_cast<char*>(aZmqMessage.data()), aZmqMessage.size()); } return aReceived; }