diff --git a/examples/chatserver/main.cpp b/examples/chatserver/main.cpp index 51f0bce..40f70c1 100644 --- a/examples/chatserver/main.cpp +++ b/examples/chatserver/main.cpp @@ -20,8 +20,11 @@ * IN THE SOFTWARE. */ +#include +#include #include #include +#include #include #include @@ -33,6 +36,15 @@ int main(int argc, char * argv[]) { QCoreApplication a(argc, argv); + // Build the command-line options + QCommandLineParser parser; + QCommandLineOption portOption(QStringList() << "p" << "port", "port to listen on", "", "8000"); + parser.addOption(portOption); + + // Parse the options that were provided and obtain the values + parser.process(a); + quint16 port = parser.value(portOption).toInt(); + // Build the hierarchy of handlers QFilesystemHandler handler(":/static"); @@ -41,8 +53,8 @@ int main(int argc, char * argv[]) QHttpServer server(&handler); - // Listen on the specified port - if(!server.listen(QHostAddress::Any, 8000)) { + // Attempt to listen on the specified port + if(!server.listen(QHostAddress::LocalHost, port)) { qCritical("Unable to listen on the specified port."); return 1; }