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;