Exemplo n.º 1
0
void _retry_write_message(tcp::iostream& stream, const T& msg) {
    while (true) {
        if (_write_message(stream, msg)) {
            return;
        }

        DEBUG("write failed, sleep and retry\n");
        stream.close();
        stream.clear();
        sleep(1);
        stream.connect("127.0.0.1", "1481");
    }
}
Exemplo n.º 2
0
	void sendMessages(unsigned sleepMillis) {
		std::cout << "In SimpleACoreDataServer sendMessages()" << std::endl;
		//WaveformSimulator wave_sim_;
		try
		{
			//wave_sim_.start(this);
			WaveformsMessage waveMessage;
			running_ = true;
			while (running_ && connected_)
			{
				if (stream_.good()) {
					//sending a waveform message
					waveMessage = waveQ_.popWait();
					std::cout << "GUIMessageSenderThread sending a waveform message" << std::endl;
					stream_ << waveMessage.toXML() << std::endl;

					while (!numericsQ_.isEmpty()) {
						std::cout << "GUIMessageSenderThread sending a numerics message!" << std::endl;
						stream_ << numericsQ_.popWait().toXML() << std::endl;
					}

				}
				else {
					connected_ = false;
				}
			  //now wait
			  //timer.expires_from_now(boost::posix_time::milliseconds(100));
			  //timer.wait();

			  //send a numerics message
			  //std::cout << "sending a numerics message!" << std::endl;
			  //stream << numerics_sim_.getNextNumericsMessage().toXML() << std::endl;
			  //now wait
			  //timer.expires_from_now(boost::posix_time::milliseconds(100));
			  //timer.wait();
			}
		}
		catch (std::exception& e)
		{
			std::cerr << "Error sending messages: " << e.what() << std::endl;
		}
		//wave_sim_.stop();
		stream_.clear();
		stream_.close();
		std::cout << "done SimpleACoreDataServer sendMessages()" << std::endl;
	}
Exemplo n.º 3
0
    void run(unsigned sleepMillis)
    {
		std::cout << "in GUIMessageSenderThread: run "
                  << sleepMillis << "ms"
                  << std::endl;

		while (running_) {
			if (!connected_) {
				std::cout << "In GUIMessageSenderThread trying to connect to: " << host_ << " " << port_ << std::endl;
				//tcp::endpoint endpoint_(boost::asio::ip::address::from_string(host_), port_);
				//tcp::endpoint endpoint_(boost::asio::ip::address::from_string(host_), port_);
				endpoint_.address(boost::asio::ip::address::from_string(host_));
				endpoint_.port(port_);
				tcp::acceptor acceptor(*io_service_, endpoint_);

				getClientConnection(acceptor);
				try {
				
					sendMessages(sleepMillis);

					acceptor.close();
					stream_.clear();
					stream_.close();
				}
				catch (std::exception& e)
				{
					std::cerr << "GUIMessageSenderThread Error in connection: " << e.what() << std::endl;
				}
				connected_ = false;
				//boost::asio::deadline_timer timer(*io_service_,boost::posix_time::milliseconds(1000));
				//timer.expires_from_now(boost::posix_time::milliseconds(1000));
				//timer.wait();
			}
		}
		std::cout << "done GUIMessageSenderThread: run "
                  << sleepMillis << "ms"
                  << std::endl;
	}