Receiving multiple requests using Simple HTTP Server in .NET

The Clever Internet .NET Suite library provides a special SimpleHttpServer component that works in single-threaded blocking mode.
 
The example starts listening to the socket in a loop. Incoming requests are accepted until you request a specific URL in your web browser.
 
using (var server = new SimpleHttpServer()) {
	do {
		server.Listen(80);

		var request = server.AcceptRequest();
		var uri = server.RequestUri;

		server.ResponseHeader.ContentType = "text/html";
		server.KeepConnection = false;

		if (uri.IndexOf("stop") > -1) {
			server.SendResponse(200, "OK", "<html><body>Server stopped.</body></html>");
			break;
		}

		server.SendResponse(200, "OK", "<html><body>Your requested the " + uri + " resource.</body></html>");
	}
	while (true);
}
 
Have questions?
Join us Facebook   YouTube   Twitter   Telegram   Newsletter
 
Kind regards
Clever Components team
www.CleverComponents.com

Add Feedback