Setting up a Listener
The first task during the client initialization is to set up a listener so the client can receive request messages from the server. Notification and solicit-response require the server to establish the connection and the client to be listening for it.
 
rwsf::MessageHandler service =
rwsf::HandlerManager::findHandler("WeatherSummaryNotificationService"); //1
 
rwsf::MessageListener listener; //2
if (transportName.empty()) {
listener = rwsf::TransportManager::findListenerByUrl(location);
} else {
listener = rwsf::TransportManager::findListener(transportName);
}
 
if (listener.isValid()) { //3
std::cout << "Starting Listener..." << std::endl << std::endl;
listener.setHandler(service);
listener.start();
}
else {
std::cerr << "Unable to find a listener of name: "
<< transportName << std::endl;
std::cerr << "Exiting." << std::endl;
return 1;
}
//1 Creates a service handler for the client. The handler WeatherSummaryNotificationService is defined in the generated file client-handlers.xml.
//2 Creates a listener object based on whether the information available is a transport name or a location.
//3 If the constructed listener is confirmed as valid, starts the listener, and registers the service handler.