Reputation: 63
I need to write an Http Handler to listen to port 80.
What should be the approach? Like should I use raw sockets to listen to port 80 within Http Handler or is there a better way to do?
I went through some tutorials as the one specified below..
http://msdn.microsoft.com/en-us/library/ms228090.aspx
But couldn't make much out of it. Any idea will appreciated.
Thanks
Upvotes: 3
Views: 2401
Reputation: 734
Socket is a very flexible way to create HTTP handlers but you have to do more with sockets. if classes like HttpListener fullfill your requirement always go for them. unless it will be something like re-inventing the wheel.
This is a working code sample which shows how to use Sockets to listen TCP requests. http://kaninotes.blogspot.com/2012/02/how-to-implement-threaded-server-socket.html
But go for HttpListener if you deal with http stuff.
Upvotes: 0
Reputation: 120380
OK. What you are looking at is a way to make a handler in IIS. If IIS isn't desired, consider using HttpListener to hook the HttpPipeline from any app.
Upvotes: 2
Reputation: 141588
An HTTP handler is just a handler that gets called by an application host, such as Internet Information Services (IIS). IIS can listen on port 80 and invoke an HTTP handler, but it is not the HTTP Handler's job to listen on a port, or even care which port the application host is listening on.
What should be the approach? Like should I use raw sockets to listen to port 80 within Http Handler or is there a better way to do?
Just use IIS, or IIS Express. Create an HTTP handler, and let IIS listen on port 80.
Upvotes: 5