Running an Iray Bridge server
Use the interface mi::neuraylib::IRemote_configuration to configure the Iray Bridge server:
- Set the port to listen on.
- Specify a directory to use as a local cache.
- Call mi::neuraylib::IRemote_server::start() to start the Iray Bridge server. When the server is successfully started, it can accept render requests from an Iray Bridge client and snapshot requests of uploaded scenes.
example_bridge_server.cpp
001 /****************************************************************************** 002 * © 1986, 2014 NVIDIA Corporation. All rights reserved. 003 *****************************************************************************/ 004 005 // examples/example_bridge_server.cpp 006 // 007 // Starts listening for Iray Bridge clients. It will accept client rendering and snapshot requests. 008 // 009 // The example expects the following command line argument: 010 // 011 // example_bridge_server <mdl_path> <path_to_disk_cache> <listen_address> 012 // 013 // mdl_path path to the MDL modules, e.g., iray-<version>/mdl 014 // path_to_disk_cache directory where the server can cache uploaded elements 015 // listen_address the address to listen on, e.g., 0.0.0.0:8998 016 017 #include <cstdio> 018 019 #include <mi/neuraylib.h> 020 021 // Include code shared by all examples. 022 #include "example_shared.h" 023 024 void run_bridge_server( mi::base::Handle<mi::neuraylib::INeuray> neuray) 025 { 026 // Create a server instance 027 mi::base::Handle<mi::neuraylib::IRemote_server> bridge_server( 028 neuray->get_api_component<mi::neuraylib::IRemote_server>()); 029 bridge_server->start(); 030 sleep_seconds( 60); 031 } 032 033 void configuration( mi::base::Handle<mi::neuraylib::INeuray> neuray, 034 const char* mdl_path, 035 const char* disk_cache_path, 036 const char* server_address) 037 { 038 // Configure the Remote server 039 mi::base::Handle<mi::neuraylib::IRemote_configuration> remote_configuration( 040 neuray->get_api_component<mi::neuraylib::IRemote_configuration>()); 041 check_success( remote_configuration.is_valid_interface()); 042 check_success( remote_configuration->set_remote_disk_cache_path( disk_cache_path) == 0); 043 check_success( remote_configuration->set_scene_export_path( disk_cache_path) == 0); 044 check_success( remote_configuration->set_remote_server_listen_address( server_address) == 0); 045 046 // set the search path for .mdl files. 047 mi::base::Handle<mi::neuraylib::IRendering_configuration> rendering_configuration( 048 neuray->get_api_component<mi::neuraylib::IRendering_configuration>()); 049 check_success( rendering_configuration.is_valid_interface()); 050 check_success( rendering_configuration->add_mdl_path( mdl_path) == 0); 051 052 // Load the FreeImage, Iray Photoreal, and cloud render plugins. 053 mi::base::Handle<mi::neuraylib::IPlugin_configuration> plugin_configuration( 054 neuray->get_api_component<mi::neuraylib::IPlugin_configuration>()); 055 #ifndef MI_PLATFORM_WINDOWS 056 check_success( plugin_configuration->load_plugin_library( "freeimage.so") == 0); 057 check_success( plugin_configuration->load_plugin_library( "libiray.so") == 0); 058 check_success( plugin_configuration->load_plugin_library( "cloud_render_server.so") == 0); 059 #else 060 check_success( plugin_configuration->load_plugin_library( "freeimage.dll") == 0); 061 check_success( plugin_configuration->load_plugin_library( "libiray.dll") == 0); 062 check_success( plugin_configuration->load_plugin_library( "cloud_render_server.dll") == 0); 063 #endif 064 } 065 066 int main( int argc, char* argv[]) 067 { 068 // Collect command line parameters 069 if( argc != 4) { 070 fprintf( stderr, 071 "Usage: example_bridge_server <mdl_path> <path_to_disk_cache> <listen_address>\n"); 072 keep_console_open(); 073 return EXIT_FAILURE; 074 } 075 const char* mdl_path = argv[1]; 076 const char* disk_cache_path = argv[2]; 077 const char* listen_address = argv[3]; 078 079 // Access the neuray library 080 mi::base::Handle<mi::neuraylib::INeuray> neuray( load_and_get_ineuray()); 081 check_success( neuray.is_valid_interface()); 082 083 // Configure the neuray library 084 configuration( neuray, mdl_path, disk_cache_path, listen_address); 085 086 // Start the neuray library 087 check_success( neuray->start() == 0); 088 089 // Prepare to listen to bridge clients 090 run_bridge_server( neuray); 091 092 // Shut down the neuray library 093 check_success( neuray->shutdown() == 0); 094 neuray = 0; 095 096 // Unload the neuray library 097 check_success( unload()); 098 099 keep_console_open(); 100 return EXIT_SUCCESS; 101 }