int main(int argc, char ** argv) { CompleteSetupSystem css; PrintExampleDescription(); // Let's enable a bit of debug-output, just to see what the server is doing SetConsoleLogLevel(MUSCLE_LOG_DEBUG); // This object contains our server's event loop. ReflectServer reflectServer; // This factory will create a StorageReflectSession object whenever // a TCP connection is received on SMART_SERVER_TCP_PORT, and // attach the StorageReflectSession to the ReflectServer for use. StorageReflectSessionFactory smartSessionFactory; if (reflectServer.PutAcceptFactory(SMART_SERVER_TCP_PORT, ReflectSessionFactoryRef(&smartSessionFactory, false)) != B_NO_ERROR) { LogTime(MUSCLE_LOG_CRITICALERROR, "Couldn't bind to TCP port %u! (Perhaps a copy of this program is already running?\n", SMART_SERVER_TCP_PORT); return 5; } // This UDP session will handle the UDP ping pong games UDPPingPongSession udpPingPong; if (reflectServer.AddNewSession(AbstractReflectSessionRef(&udpPingPong, false)) != B_NO_ERROR) { LogTime(MUSCLE_LOG_CRITICALERROR, "Couldn't add UDP ping pong session!\n"); return 5; } LogTime(MUSCLE_LOG_INFO, "example_7_smart_server_wth_udp_pingpong is listening for incoming TCP connections on port %u\n", SMART_SERVER_TCP_PORT); LogTime(MUSCLE_LOG_INFO, "Try running one or more instances of example_5_smart_client to connect/chat/subscribe!\n"); LogTime(MUSCLE_LOG_INFO, "\n"); // Our server's event loop will run here -- ServerProcessLoop() return until it's time for the server to exit if (reflectServer.ServerProcessLoop() == B_NO_ERROR) { LogTime(MUSCLE_LOG_INFO, "example_7_smart_server_wth_udp_pingpong is exiting normally.\n"); } else LogTime(MUSCLE_LOG_ERROR, "example_7_smart_server_wth_udp_pingpong is exiting due to an error.\n"); // Make sure our server lets go of all of its sessions and factories // before they are destroyed (necessary only because we may have // allocated some of them on the stack rather than on the heap) reflectServer.Cleanup(); return 0; }
int main(int argc, char ** argv) { CompleteSetupSystem css; PrintExampleDescription(); // This object contains our server's event loop. ReflectServer reflectServer; // This factory will create a DumbReflectSession object whenever // a TCP connection is received on DUMB_SERVER_TCP_PORT, and // attach the DumbReflectSession to the ReflectServer for use. MyDumbReflectSessionFactory dumbSessionFactory; if (reflectServer.PutAcceptFactory(DUMB_SERVER_TCP_PORT, ReflectSessionFactoryRef(&dumbSessionFactory, false)) != B_NO_ERROR) { LogTime(MUSCLE_LOG_CRITICALERROR, "Couldn't bind to TCP port %u! (Perhaps a copy of this program is already running?\n", DUMB_SERVER_TCP_PORT); return 5; } // Here's where our server will spend all of its time LogTime(MUSCLE_LOG_INFO, "example_3_annotated_dumb_server is listening for incoming TCP connections on port %u\n", DUMB_SERVER_TCP_PORT); LogTime(MUSCLE_LOG_INFO, "Try running one or more instances of example_2_dumb_client to connect and chat!\n"); printf("\n"); // Our server's event loop will run here -- ServerProcessLoop() return until it's time for the server to exit if (reflectServer.ServerProcessLoop() == B_NO_ERROR) { LogTime(MUSCLE_LOG_INFO, "example_3_annotated_dumb_server is exiting normally.\n"); } else LogTime(MUSCLE_LOG_ERROR, "example_3_annotated_dumb_server is exiting due to an error.\n"); // Make sure our server lets go of all of its sessions and factories // before they are destroyed (necessary only because we may have // allocated some of them on the stack rather than on the heap) reflectServer.Cleanup(); return 0; }