17 #include <QCoreApplication> 18 #include <QHostAddress> 19 #include <QNetworkInterface> 48 bool started = this->listen(QHostAddress::Any, port);
53 std::cout <<
"Server IP adresses: " << std::endl;
54 foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces())
56 if (interface.flags().testFlag(QNetworkInterface::IsRunning))
57 foreach (QNetworkAddressEntry entry, interface.addressEntries())
59 if ( interface.hardwareAddress() !=
"00:00:00:00:00:00" && entry.ip().toString() !=
"127.0.0.1" && entry.ip().toString().contains(
".") )
60 std::cout <<
string_cast(interface.name()) <<
" " << entry.ip().toString() << std::endl;
64 std::cout << QString(
"Server is listening to port %2").arg(this->serverPort()).toStdString() << std::endl;
69 std::cout <<
"Server failed to start. Error: " << this->errorString().toStdString() << std::endl;
80 std::cout <<
"Server: Incoming connection..." << std::endl;
84 reportError(
"The image server can only handle a single connection.");
88 mSocket =
new QTcpSocket();
89 connect(mSocket, SIGNAL(disconnected()),
this, SLOT(socketDisconnectedSlot()));
90 mSocket->setSocketDescriptor(socketDescriptor);
91 QString clientName = mSocket->localAddress().toString();
92 report(
"Connected to "+clientName+
". Session started.");
95 mImageSender->startStreaming(sender);
98 void ImageServer::socketDisconnectedSlot()
101 mImageSender->stopStreaming();
105 QString clientName = mSocket->localAddress().toString();
106 report(
"Disconnected from "+clientName+
". Session ended.");
107 mSocket->deleteLater();
114 std::cout << std::endl;
115 std::cout << std::endl;
116 std::cout <<
"Press Ctrl + C to close the server."<< std::endl;
117 std::cout << std::endl;
122 std::stringstream ss;
125 ss <<
"Usage: " << applicationName <<
" (--arg <argval>)*" << std::endl;
126 ss <<
" --port : Tcp/IP port # (default=18333)" << std::endl;
130 ss <<
" Select one of the types below:" << std::endl;
133 for (
int i = 0; i < types.size(); ++i)
137 ss <<
" type = " << types[i].toStdString() << std::endl;
138 for (
int j = 0; j < args.size(); ++j)
139 ss <<
" " << args[j].toStdString() << std::endl;
QString qstring_cast(const T &val)
void reportError(QString msg)
StreamerPtr getFromArguments(StringMap args)
QStringList getSenderTypes() const
all available sender types
std::string string_cast(const T &val)
ImageServer(QObject *parent=NULL)
std::map< QString, QString > StringMap
static void printHelpText()
static QString getArgumentHelpText(QString applicationName)
QStringList getArgumentDescription(QString type) const
arguments for one streamer
Factory class for creating streamer objects.
void incomingConnection(qintptr socketDescriptor)
bool startListen(int port)
StringMap extractCommandlineOptions(QStringList cmdline)
boost::shared_ptr< Sender > SenderPtr
QString getDefaultSenderType() const
Namespace for all CustusX production code.