本文整理汇总了C++中UdpServer::startServer方法的典型用法代码示例。如果您正苦于以下问题:C++ UdpServer::startServer方法的具体用法?C++ UdpServer::startServer怎么用?C++ UdpServer::startServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UdpServer
的用法示例。
在下文中一共展示了UdpServer::startServer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
UdpServer server;
QString ttyPort = "/dev/ttyACM0";
int baudrate = 115200;
int udpPort = 27800;
QStringList args = QCoreApplication::arguments();
for (int i = 0;i < args.size();i++) {
// Skip the program argument
if (i == 0) {
continue;
}
QString str = args.at(i).toLower();
// Skip path argument
if (i >= args.size() && args.size() >= 3) {
break;
}
bool dash = str.startsWith("-") && !str.startsWith("--");
bool found = false;
if ((dash && str.contains('h')) || str == "--help") {
showHelp();
found = true;
return 0;
}
if ((dash && str.contains('t')) || str == "--ttyport") {
if ((i - 1) < args.size()) {
i++;
ttyPort = args.at(i);
found = true;
}
}
if ((dash && str.contains('b')) || str == "--baudrate") {
if ((i - 1) < args.size()) {
i++;
bool ok;
baudrate = args.at(i).toInt(&ok);
found = ok;
}
}
if ((dash && str.contains('u')) || str == "--udpport") {
if ((i - 1) < args.size()) {
i++;
bool ok;
udpPort = args.at(i).toInt(&ok);
found = ok;
}
}
if (!found) {
if (dash) {
qCritical() << "At least one of the flags is invalid:" << str;
} else {
qCritical() << "Invalid option:" << str;
}
showHelp();
return 1;
}
}
qDebug() << "Serial Port:" << ttyPort;
qDebug() << "Baudrate:" << baudrate;
qDebug() << "UDP Port:" << udpPort;
if (server.startServer(ttyPort, baudrate, udpPort)) {
qDebug() << "The server was successfully started.";
qDebug() << "UDP Port:" << server.getUdpPort();
qDebug() << "Serial Port:" << server.getSerialPortPath();
} else {
qCritical() << "Errors occured. Exiting...";
QTimer::singleShot(500, &a, SLOT(quit()));
}
return a.exec();
}