38 #include <QCoreApplication>
39 #include <QHostAddress>
40 #include <QNetworkInterface>
69 bool started = this->listen(QHostAddress::Any, port);
74 std::cout <<
"Server IP adresses: " << std::endl;
75 foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces())
77 if (interface.flags().testFlag(QNetworkInterface::IsRunning))
78 foreach (QNetworkAddressEntry entry, interface.addressEntries())
80 if ( interface.hardwareAddress() !=
"00:00:00:00:00:00" && entry.ip().toString() !=
"127.0.0.1" && entry.ip().toString().contains(
".") )
81 std::cout <<
string_cast(interface.name()) <<
" " << entry.ip().toString() << std::endl;
85 std::cout << QString(
"Server is listening to port %2").arg(this->serverPort()).toStdString() << std::endl;
90 std::cout <<
"Server failed to start. Error: " << this->errorString().toStdString() << std::endl;
101 std::cout <<
"Server: Incoming connection..." << std::endl;
105 reportError(
"The image server can only handle a single connection.");
109 mSocket =
new QTcpSocket();
110 connect(mSocket, SIGNAL(disconnected()),
this, SLOT(socketDisconnectedSlot()));
111 mSocket->setSocketDescriptor(socketDescriptor);
112 QString clientName = mSocket->localAddress().toString();
113 report(
"Connected to "+clientName+
". Session started.");
116 mImageSender->startStreaming(sender);
119 void ImageServer::socketDisconnectedSlot()
122 mImageSender->stopStreaming();
126 QString clientName = mSocket->localAddress().toString();
127 report(
"Disconnected from "+clientName+
". Session ended.");
128 mSocket->deleteLater();
135 std::cout << std::endl;
136 std::cout << std::endl;
137 std::cout <<
"Press Ctrl + C to close the server."<< std::endl;
138 std::cout << std::endl;
143 std::stringstream ss;
146 ss <<
"Usage: " << applicationName <<
" (--arg <argval>)*" << std::endl;
147 ss <<
" --port : Tcp/IP port # (default=18333)" << std::endl;
151 ss <<
" Select one of the types below:" << std::endl;
154 for (
int i = 0; i < types.size(); ++i)
158 ss <<
" type = " << types[i].toStdString() << std::endl;
159 for (
int j = 0; j < args.size(); ++j)
160 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