Path: blob/main/src/utils/iodevices/OutputDevice_Network.h
169678 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2006-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file OutputDevice_Network.h14/// @author Michael Behrisch15/// @author Daniel Krajzewicz16/// @author Felix Brack17/// @date 200618///19// An output device for TCP/IP Network connections20/****************************************************************************/21#pragma once22#include <config.h>2324#include "foreign/tcpip/socket.h"25#include "foreign/tcpip/storage.h"26#include "OutputDevice.h"27#include <utils/common/UtilExceptions.h>28#include <string>29#include <iostream>30#include <sstream>313233// ==========================================================================34// class definitions35// ==========================================================================36/**37* @class OutputDevice_Network38* @brief An output device for TCP/IP network connections39*40* The implementation uses a portable socket implementation from the Shawn41* project (shawn.sf.net) located in src/foreign/tcpip/socket.h. It uses42* an internal storage for the messages, which is sent via the socket when43* "postWriteHook" is called.44* @see postWriteHook45*/46class OutputDevice_Network : public OutputDevice {47public:48/** @brief Constructor49*50* @param[in] host The host to connect51* @param[in] port The port to connect52* @exception IOError If the connection could not be established53*/54OutputDevice_Network(const std::string& host,55const int port);565758/// @brief Destructor59~OutputDevice_Network();606162protected:63/// @name Methods that override/implement OutputDevice-methods64/// @{6566/** @brief Returns the associated ostream67*68* The stream is an ostringstream, actually, into which the message69* is written. It is sent when postWriteHook is called.70*71* @return The used stream72* @see postWriteHook73*/74std::ostream& getOStream();757677/** @brief Sends the data which was written to the string stream over the socket.78*79* Converts the stored message into a vector of chars and sends them via to80* the socket implementation. Resets the message, afterwards.81*/82virtual void postWriteHook();83/// @}8485private:86/// @brief packet buffer87std::ostringstream myMessage;8889/// @brief the socket to transfer the data90tcpip::Socket* mySocket;9192};939495