Creating a web server that responds to every incom

2019-05-02 04:58发布

问题:

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?

回答1:

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...



回答2:

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