// Create and start server thread public ServerThread(HttpListenerContext context, UserListGenerator userLister, ChangeListGenerator changeLister) { this.context = context; this.userLister = userLister; this.changeLister = changeLister; new Thread(new ThreadStart(Run)).Start(); }
/// <summary> /// Starts the main server thread. All requests are handled in seperate threads /// </summary> /// <param name="args">No arguments accepted</param> static void Main(string[] args) { // Create objects needed for MESAP Server access root = new M4DBO.dboRoot(); mspErrDboInitEnum rootError = root.Initialize("", mspM4AppEnum.mspM4AppOEM, false, TITLE); if (rootError != mspErrDboInitEnum.mspErrNone) { WriteStatus("Can not connect to MESAP server."); WriteStatus("Stopped."); WriteStatus("Press any key to close..."); Console.ReadKey(); return; } // Login to MESAP Message Server mspErrDboLoginEnum loginError = root.Login(Private.User, Private.Password, USE_SYSTEM_DB, Private.SystemPassword); if (loginError != mspErrDboLoginEnum.mspErrNone) { WriteStatus("Can not log in as " + Private.User + "!"); WriteStatus("Stopped."); WriteStatus("Press any key to close..."); Console.ReadKey(); return; } userLister = new UserListGenerator(root); changeLister = new ChangeListGenerator(root); // Start listing on the given port with given prefixes listener = new HttpListener(); listener.Prefixes.Add("http://localhost:" + PORT + "/users/"); //listener.Prefixes.Add("http://172.22.2.96:" + PORT + "/users/"); listener.Prefixes.Add("http://localhost:" + PORT + "/changes/"); //listener.Prefixes.Add("http://172.22.2.96:" + PORT + "/changes/"); listener.Start(); WriteStatus("Server up and running."); WriteStatus("Listening to port " + PORT + "."); WriteStatus("Type \"" + STOP_COMMAND + "\" to terminate the server."); // Start the thread which calls the method 'StartListen' Thread worker = new Thread(new ThreadStart(StartListen)); worker.Start(); // Read commands String cmd = ""; while (!cmd.ToLower().Equals(STOP_COMMAND)) { cmd = Console.ReadLine(); if (!cmd.ToLower().Equals(STOP_COMMAND)) { Console.WriteLine("Unknown command: " + cmd); } } // Stop worker thread worker.Abort(); // Stop listener listener.Stop(); // Log out from MESAP system root.Logout(); }