01 #include <QtCore/QCoreApplication>
02 #include <QtCore/QStringList>
03 #include <QtNetwork/QHostAddress>
04 #include <QtNetwork/QTcpSocket>
05
06 #include <iostream>
07
08 int main(int argc, char *argv[])
09 {
10   QCoreApplication app(argc, argv);
11
12   QString host = app.arguments().at(1);
13   int port = 80;
14
15   QTcpSocket socket;
16   socket.connectToHost(host, port);
17
18   if (!socket.waitForConnected(1000)) {
19     std::cout << "Could not connect" << std::endl;
20     return 10;
21   }
22
23   QHostAddress peerAddress = socket.peerAddress();
24   QString address = peerAddress.toString();
25   std::cout << "Connected to "
26             << address.toAscii().constData() << std::endl;
27   socket.close();
28   return 0;
29 }