I'd like to create a web server that responds to every incoming request with a simple "Hello" message in C#.
How do I do that?
I'd like to create a web server that responds to every incoming request with a simple "Hello" message in C#.
How do I do that?
How much of it do you need to do from scratch? It's pretty simple to do this if you're allowed to use HttpListener
.
Otherwise, you might want to look at TcpListener
- accept a socket connection, read data from it, and write a response. Admittedly it's somewhat easier if you can answer every request with "Hello" as you don't need to really parse it...
You need to implement some Socket Programming. use System.Net.Sockets.TcpListener
class to listen incomming requests.
// Use port number 80 for incomming HTTP requests.
TcpListener listener = new TcpListener(80);
// This method return a socket to handle incomming client's request...
listener.AcceptSocket();
Also you need to know how handle multithreading programming. because of this you need to create a thread and read just incomming requests and synchronously save client's thread and socket in a collection and process data!
I don't want to disappointed you but you need a little bit of parsing strings using Teory of Languages and Machines!
You can read an article on CodeProject
http://www.codeproject.com/KB/IP/mywebserver.aspx
There is also a project on codeplex
http://webserver.codeplex.com/
You will need Sockets, Multithreading and the RFC http://www.faqs.org/rfcs/rfc2616.html