本文整理汇总了C++中QUdpSocket::isValid方法的典型用法代码示例。如果您正苦于以下问题:C++ QUdpSocket::isValid方法的具体用法?C++ QUdpSocket::isValid怎么用?C++ QUdpSocket::isValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QUdpSocket
的用法示例。
在下文中一共展示了QUdpSocket::isValid方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
//help output
if(a.arguments().contains("help"))
{
MSG("### OSCGrabber HELP ###");
MSG(" ");
MSG("The following Arguments are available:");
MSG(" osc-server-address (address to send osc messages to) [default: 127.0.0.1]");
MSG(" osc-send-port (port to send osc messages to) [default: 7000]");
MSG(" osc-listen-port (port on wich OSCGrabber is listening for incomming osc messages) [default: 9001]");
MSG(" udp-send-address (address to send udp converted messages to) [default: 127.0.0.1]");
MSG(" udp-send-port (port to send udp converted messages to) [default: 7799]");
MSG(" udp-listen-port (port on wich OSCGrabber is listening for incomming udp messages) [default: 7788]");
MSG(" ");
MSG("examaple calls:");
MSG(" OSCGrabber osc-listen-port 7000 osc-server-address 1.2.3.4");
MSG(" ");
MSG("Type 'help' for this message.");
a.exit();
return a.exec();
}
//read command line arguments
int oscListenPort = 9001;
if(a.arguments().contains("osc-listen-port"))
oscListenPort = a.arguments().at(a.arguments().indexOf(QRegExp("osc-listen-port"))+1).toInt();
QString oscServerAddress = "127.0.0.1";
if(a.arguments().contains("osc-server-address"))
oscServerAddress = a.arguments().at(a.arguments().indexOf(QRegExp("osc-server-address"))+1);
int oscSendPort = 9000;
if(a.arguments().contains("osc-send-port"))
oscSendPort = a.arguments().at(a.arguments().indexOf(QRegExp("osc-send-port"))+1).toInt();
int udpSendPort = 7799;
if(a.arguments().contains("udp-send-port"))
udpSendPort = a.arguments().at(a.arguments().indexOf(QRegExp("udp-send-port"))+1).toInt();
QString udpSendAddress = "127.0.0.1";
if(a.arguments().contains("udp-send-address"))
udpSendAddress = a.arguments().at(a.arguments().indexOf(QRegExp("udp-send-address"))+1);
int udpListenPort = 7788;
if(a.arguments().contains("udp-listen-port"))
udpListenPort = a.arguments().at(a.arguments().indexOf(QRegExp("udp-listen-port"))+1).toInt();
//start creating the services
MSG("### [Creating] UDP service at Port "<<udpListenPort);
MSG("### Sending to "<<udpSendAddress.toStdString());
QUdpSocket *listenSocket = new QUdpSocket(&a);
listenSocket->bind(QHostAddress::AnyIPv4, udpListenPort);
if(!listenSocket->isValid())
{
MSG("Couldn't creat udp service at port "<<udpSendPort<<" . Port already occupied?");
a.exit();
return 0; //a.exec();
}
MSG("### [Launching] OSC Bridge to address "<<oscServerAddress.toStdString()<<" "<<oscListenPort)
lo::ServerThread * server = new lo::ServerThread(oscListenPort);
server->start();
if (!server->is_valid()) { //this check isn't working. why?
MSG("Couldn't creat osc service listening to port "<<oscListenPort<<" . Port already occupied?");
a.exit();
return 0; //a.exec();
}
MSG("### --> Listening to Port: "<<oscListenPort);
lo::string_type address(oscServerAddress.toStdString());
lo::Address * oscSender = new lo::Address(address, oscSendPort);
// lo::Address * oscSender = new lo::Address("localhost", oscSendPort);
MSG("### --> Writing on Port: "<<oscSendPort);
//####################################################################################
//####################################################################################
// OSC to UDP
//####################################################################################
//####################################################################################
QUdpSocket *senderSocket = new QUdpSocket(&a);
server->add_method(NULL, NULL, [=](const char *path, const lo::Message& msg)
{
// msg.print();
QString type = QString::fromStdString(msg.types());
QString data(path);
data.append("%");
data.append(type);
data.append("%");
for (int i = 0; i < msg.argc(); i++) {
//.........这里部分代码省略.........