简体   繁体   English

使用Http Handlers监听端口80

[英]Using Http Handlers to listen to port 80

I need to write an Http Handler to listen to port 80. 我需要编写一个Http Handler来监听端口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? 我应该使用原始套接字来监听Http Handler中的端口80,还是有更好的方法呢?

I went through some tutorials as the one specified below.. 我经历了一些教程,如下面指定的那样。

http://msdn.microsoft.com/en-us/library/ms228090.aspx http://msdn.microsoft.com/en-us/library/ms228090.aspx

But couldn't make much out of it. 但无法从中获益。 Any idea will appreciated. 任何想法都会赞赏。

Thanks 谢谢

An HTTP handler is just a handler that gets called by an application host, such as Internet Information Services (IIS). HTTP处理程序只是由应用程序主机(如Internet信息服务(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. IIS 可以侦听端口80并调用HTTP处理程序,但侦听端口不是HTTP处理程序的工作,甚至不关心应用程序主机正在侦听哪个端口。

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? 我应该使用原始套接字来监听Http Handler中的端口80,还是有更好的方法呢?

Just use IIS, or IIS Express . 只需使用IIS或IIS Express Create an HTTP handler, and let IIS listen on port 80. 创建一个HTTP处理程序,让IIS侦听端口80。

OK. 好。 What you are looking at is a way to make a handler in IIS. 你在看什么是一种在IIS中制作处​​理程序的方法。 If IIS isn't desired, consider using HttpListener to hook the HttpPipeline from any app. 如果不需要IIS,请考虑使用HttpListener从任何应用程序挂钩HttpPipeline。

Socket is a very flexible way to create HTTP handlers but you have to do more with sockets. Socket是一种非常灵活的创建HTTP处理程序的方法,但你必须使用套接字做更多的事情。 if classes like HttpListener fullfill your requirement always go for them. 如果像HttpListener这样的类满足你的要求总是适合他们。 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. 这是一个工作代码示例,演示了如何使用套接字来侦听TCP请求。 http://kaninotes.blogspot.com/2012/02/how-to-implement-threaded-server-socket.html http://kaninotes.blogspot.com/2012/02/how-to-implement-threaded-server-socket.html

But go for HttpListener if you deal with http stuff. 但如果你处理http的东西,请去HttpListener

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM