26 #include <boost/property_tree/ptree.hpp>
27 #include <boost/property_tree/xml_parser.hpp>
29 using boost::property_tree::ptree;
36 m_connection->setParent(
this);
37 connect(m_connection, SIGNAL(ReceivedMessage(
const QByteArray&)),
this, SLOT(Receive(
const QByteArray&)));
38 connect(m_connection, SIGNAL(ConnectionClosed()),
this, SIGNAL(
Ended()));
39 connect(m_connection, SIGNAL(
Error(
const std::string&)),
this, SIGNAL(
Error(
const std::string&)));
40 connect(m_connection, SIGNAL(
Error(
const std::string&)),
this, SIGNAL(
Ended()));
46 QTcpSocket *socket =
new QTcpSocket();
48 if (socket->waitForConnected(2000)) {
51 connect(m_connection, SIGNAL(ReceivedMessage(
const QByteArray&)),
this, SLOT(Receive(
const QByteArray&)));
52 connect(m_connection, SIGNAL(ConnectionClosed()),
this, SIGNAL(
Ended()));
53 connect(m_connection, SIGNAL(
Error(
const std::string&)),
this, SIGNAL(
Error(
const std::string&)));
54 connect(m_connection, SIGNAL(
Error(
const std::string&)),
this, SIGNAL(
Ended()));
57 m_connection =
nullptr;
65 std::string Protocol::GetClientIP()
const {
66 return m_connection->GetPeerAddress();
69 int Protocol::GetClientPort()
const {
70 return m_connection->GetPeerPort();
75 return (m_connection !=
nullptr && m_connection->
IsConnected());
80 std::ostringstream stream;
81 write_xml(stream, pt);
82 QByteArray message(stream.str().data(), stream.str().size());
86 void Protocol::Receive(
const QByteArray &message)
88 std::istringstream s(message.data());
Protocol(QTcpSocket *socket, QObject *parent=nullptr)
Constructor.
Interface for ServerInfo.
void Error(const std::string &error)
Signal emitted when an error occured.
Interface for Connection.
void SendPtree(const boost::property_tree::ptree &pt)
Sends a ptree over the connection.
int GetPort()
Return the port of the server.
void SendMessage(const QByteArray &message)
Sends a message over the connection.
void Ended()
Signal emitted when the protocol has ended and the connection is closed.
bool IsConnected()
Check if still connected.
Class managing a TCP stream of messages.
virtual ~Protocol()
Destructor.
QString GetAddress()
Return the address of the server.
Class for storing server info used on client-side.
virtual void ReceivePtree(const boost::property_tree::ptree &pt)=0
Method called when a ptree was received over the connection.
Namespace for SimPT parameter explorer package.
bool IsConnected()
Check if still connected.
see the online Qt documentation