public static void AddService(WebService service) { services.Add(service); }
internal static void AddService(WebService service) { services.Add(service); }
public static void AddService(WebService service) { string uri = service.ServiceURI; _web_services.TryAdd(uri, service); }
public static bool Start(int port, int number_threads) { // Create thread to listen for incoming clients new Thread(() => { // Init and start server server = new TcpListener(IPAddress.Any, port); server.Start(); threadPool.Start((ushort)number_threads); while (true) { TcpClient client; try { client = server.AcceptTcpClient(); } catch { break; } // Make thread task function and add it to the ThreadPool threadPool.AddTask(() => { WebRequest req = BuildRequest(client); // Invalid request object, close connection. if (null != req) { // Handle that request // Find services that will handle the request URI bool foundService = false; int longestPrefix = 0; WebService serviceToUse = null; foreach (var service in services) { if (req.URI.StartsWith(service.ServiceURI)) { // We'll select the service that has a longer prefix of the request URI and use it if (service.ServiceURI.Length > longestPrefix) { longestPrefix = service.ServiceURI.Length; serviceToUse = service; } } } if (null == serviceToUse) { // send 404 reponse req.WriteNotFoundResponse(""); } else { // "Handle" request serviceToUse.Handler(req); } } client.Close(); }); } }).Start(); return(true); }
public static void AddService(WebService service) { //added to the list of services that the web server supports servicesList.TryAdd(service.ServiceURI, service); }