int main(int argc, char* argv[]) { OCConnectivityType connectivityType = OC_IPV4; if(argc == 2) { try { std::size_t inputValLen; int optionSelected = std::stoi(argv[1], &inputValLen); if(inputValLen == strlen(argv[1])) { if(optionSelected == 0) { connectivityType = OC_IPV4; } else if(optionSelected == 1) { // TODO: re-enable IPv4/IPv6 command line selection when IPv6 is supported // connectivityType = OC_IPV6; connectivityType = OC_IPV4; std::cout << "IPv6 not currently supported. Using default IPv4" << std::endl; } else { std::cout << "Invalid connectivity type selected. Using default IPv4" << std::endl; } } else { std::cout << "Invalid connectivity type selected. Using default IPv4" << std::endl; } } catch(std::exception& ) { std::cout << "Invalid input argument. Using IPv4 as connectivity type" << std::endl; } } else { std::cout<< "Usage simpleclientserver <ConnectivityType(0|1)>" << std::endl; std::cout<< " ConnectivityType: Default IPv4" << std::endl; std::cout << " ConnectivityType : 0 - IPv4" << std::endl; std::cout << " ConnectivityType : 1 - IPv6 (not currently supported)" << std::endl; } PlatformConfig cfg { OC::ServiceType::InProc, OC::ModeType::Both, "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces 0, // Uses randomly available port OC::QualityOfService::LowQos }; OCPlatform::Configure(cfg); FooResource fooRes; try { if(!fooRes.createResource()) { return -1; } ClientWorker cw(connectivityType); cw.start(); } catch(OCException& e) { std::cout<< "Exception in main: "<<e.what()<<std::endl; } return 0; }
int main(int argc, char* argv[]) { OCConnectivityType connectivityType = CT_ADAPTER_IP; if(argc == 2) { try { std::size_t inputValLen; int optionSelected = std::stoi(argv[1], &inputValLen); if(inputValLen == strlen(argv[1])) { if(optionSelected == 0) { std::cout << "Using IP."<< std::endl; connectivityType = CT_ADAPTER_IP; } else { std::cout << "Invalid connectivity type selected. Using default IP" << std::endl; } } else { std::cout << "Invalid connectivity type selected. Using default IP" << std::endl; } } catch(std::exception& ) { std::cout << "Invalid input argument. Using IP as connectivity type" << std::endl; } } else { printUsage(); } PlatformConfig cfg { OC::ServiceType::InProc, OC::ModeType::Both, "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces 0, // Uses randomly available port OC::QualityOfService::LowQos }; OCPlatform::Configure(cfg); FooResource fooRes; try { if(!fooRes.createResource()) { return -1; } ClientWorker cw(connectivityType); cw.start(); } catch(OCException& e) { std::cout<< "Exception in main: "<<e.what()<<std::endl; } return 0; }